2019-01-15 14:52:33 +01:00
|
|
|
import { Transaction } from 'sequelize'
|
2020-11-20 11:21:08 +01:00
|
|
|
import { getVideoDislikeActivityPubUrlByLocalActor } from '../url'
|
2019-01-15 14:52:33 +01:00
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
|
import { ActivityAudience, ActivityDislike } from '../../../../shared/models/activitypub'
|
|
|
|
import { sendVideoRelatedActivity } from './utils'
|
|
|
|
import { audiencify, getAudience } from '../audience'
|
2020-06-18 10:45:25 +02:00
|
|
|
import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models'
|
2019-01-15 14:52:33 +01:00
|
|
|
|
2020-01-31 16:56:52 +01:00
|
|
|
function sendDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
|
2019-01-15 14:52:33 +01:00
|
|
|
logger.info('Creating job to dislike %s.', video.url)
|
|
|
|
|
|
|
|
const activityBuilder = (audience: ActivityAudience) => {
|
2020-11-20 11:21:08 +01:00
|
|
|
const url = getVideoDislikeActivityPubUrlByLocalActor(byActor, video)
|
2019-01-15 14:52:33 +01:00
|
|
|
|
|
|
|
return buildDislikeActivity(url, byActor, video, audience)
|
|
|
|
}
|
|
|
|
|
|
|
|
return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t })
|
|
|
|
}
|
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
function buildDislikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityDislike {
|
2019-01-15 14:52:33 +01:00
|
|
|
if (!audience) audience = getAudience(byActor)
|
|
|
|
|
|
|
|
return audiencify(
|
|
|
|
{
|
|
|
|
id: url,
|
|
|
|
type: 'Dislike' as 'Dislike',
|
|
|
|
actor: byActor.url,
|
|
|
|
object: video.url
|
|
|
|
},
|
|
|
|
audience
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendDislike,
|
|
|
|
buildDislikeActivity
|
|
|
|
}
|