PeerTube/server/lib/activitypub/send/send-like.ts

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-11-23 14:19:55 +01:00
import { Transaction } from 'sequelize'
2017-12-12 17:53:50 +01:00
import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
2017-12-14 17:38:41 +01:00
import { ActorModel } from '../../../models/activitypub/actor'
2017-12-12 17:53:50 +01:00
import { VideoModel } from '../../../models/video/video'
2017-11-23 14:19:55 +01:00
import { getVideoLikeActivityPubUrl } from '../url'
2018-09-14 16:51:35 +02:00
import { sendVideoRelatedActivity } from './utils'
import { audiencify, getAudience } from '../audience'
2018-07-30 17:02:40 +02:00
import { logger } from '../../../helpers/logger'
2017-11-23 14:19:55 +01:00
async function sendLike (byActor: ActorModel, video: VideoModel, 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) => {
const url = getVideoLikeActivityPubUrl(byActor, video)
2017-11-23 14:19:55 +01:00
2018-09-14 16:51:35 +02:00
return buildLikeActivity(url, byActor, video, audience)
}
2017-11-23 14:19:55 +01:00
2018-09-14 16:51:35 +02:00
return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t })
2017-11-23 14:19:55 +01:00
}
2018-09-11 16:27:07 +02:00
function buildLikeActivity (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
if (!audience) audience = getAudience(byActor)
return audiencify(
{
id: url,
2018-11-14 15:01:28 +01:00
type: 'Like' as 'Like',
actor: byActor.url,
object: video.url
},
audience
)
2017-11-23 14:19:55 +01:00
}
// ---------------------------------------------------------------------------
export {
sendLike,
2018-09-11 16:27:07 +02:00
buildLikeActivity
2017-11-23 14:19:55 +01:00
}