2019-01-15 08:52:33 -05:00
|
|
|
import { Transaction } from 'sequelize'
|
2022-03-18 06:17:35 -04:00
|
|
|
import { ActivityAudience, ActivityDislike } from '@shared/models'
|
2019-01-15 08:52:33 -05:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2020-06-18 04:45:25 -04:00
|
|
|
import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models'
|
2022-03-18 06:17:35 -04:00
|
|
|
import { audiencify, getAudience } from '../audience'
|
|
|
|
import { getVideoDislikeActivityPubUrlByLocalActor } from '../url'
|
|
|
|
import { sendVideoActivityToOrigin } from './shared/send-utils'
|
2019-01-15 08:52:33 -05:00
|
|
|
|
2022-03-23 11:14:33 -04:00
|
|
|
function sendDislike (byActor: MActor, video: MVideoAccountLight, transaction: Transaction) {
|
2019-01-15 08:52:33 -05:00
|
|
|
logger.info('Creating job to dislike %s.', video.url)
|
|
|
|
|
|
|
|
const activityBuilder = (audience: ActivityAudience) => {
|
2020-11-20 05:21:08 -05:00
|
|
|
const url = getVideoDislikeActivityPubUrlByLocalActor(byActor, video)
|
2019-01-15 08:52:33 -05:00
|
|
|
|
|
|
|
return buildDislikeActivity(url, byActor, video, audience)
|
|
|
|
}
|
|
|
|
|
2022-03-23 11:14:33 -04:00
|
|
|
return sendVideoActivityToOrigin(activityBuilder, { byActor, video, transaction, contextType: 'Rate' })
|
2019-01-15 08:52:33 -05:00
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
function buildDislikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityDislike {
|
2019-01-15 08:52:33 -05:00
|
|
|
if (!audience) audience = getAudience(byActor)
|
|
|
|
|
|
|
|
return audiencify(
|
|
|
|
{
|
|
|
|
id: url,
|
|
|
|
type: 'Dislike' as 'Dislike',
|
|
|
|
actor: byActor.url,
|
|
|
|
object: video.url
|
|
|
|
},
|
|
|
|
audience
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendDislike,
|
|
|
|
buildDislikeActivity
|
|
|
|
}
|