2017-11-23 14:19:55 +01:00
|
|
|
import { Transaction } from 'sequelize'
|
2022-03-18 11:17:35 +01:00
|
|
|
import { ActivityAudience, ActivityLike } from '@shared/models'
|
2018-07-30 17:02:40 +02:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2020-06-18 10:45:25 +02:00
|
|
|
import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models'
|
2022-03-18 11:17:35 +01:00
|
|
|
import { audiencify, getAudience } from '../audience'
|
|
|
|
import { getVideoLikeActivityPubUrlByLocalActor } from '../url'
|
|
|
|
import { sendVideoActivityToOrigin } from './shared/send-utils'
|
2017-11-23 14:19:55 +01:00
|
|
|
|
2020-01-31 16:56:52 +01:00
|
|
|
function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
|
2018-07-30 17:02:40 +02:00
|
|
|
logger.info('Creating job to like %s.', video.url)
|
|
|
|
|
2018-09-14 16:51:35 +02:00
|
|
|
const activityBuilder = (audience: ActivityAudience) => {
|
2020-11-20 11:21:08 +01:00
|
|
|
const url = getVideoLikeActivityPubUrlByLocalActor(byActor, video)
|
2017-11-23 14:19:55 +01:00
|
|
|
|
2018-09-14 16:51:35 +02:00
|
|
|
return buildLikeActivity(url, byActor, video, audience)
|
2018-03-27 13:33:56 +02:00
|
|
|
}
|
2017-11-23 14:19:55 +01:00
|
|
|
|
2022-03-18 11:17:35 +01:00
|
|
|
return sendVideoActivityToOrigin(activityBuilder, { byActor, video, transaction: t })
|
2017-11-23 14:19:55 +01:00
|
|
|
}
|
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
function buildLikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityLike {
|
2018-06-12 20:04:58 +02:00
|
|
|
if (!audience) audience = getAudience(byActor)
|
|
|
|
|
|
|
|
return audiencify(
|
|
|
|
{
|
|
|
|
id: url,
|
2018-11-14 15:01:28 +01:00
|
|
|
type: 'Like' as 'Like',
|
2018-06-12 20:04:58 +02:00
|
|
|
actor: byActor.url,
|
|
|
|
object: video.url
|
|
|
|
},
|
|
|
|
audience
|
|
|
|
)
|
2017-11-23 14:19:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-03-27 13:33:56 +02:00
|
|
|
sendLike,
|
2018-09-11 16:27:07 +02:00
|
|
|
buildLikeActivity
|
2017-11-23 14:19:55 +01:00
|
|
|
}
|