]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-like.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-like.ts
1 import { Transaction } from 'sequelize'
2 import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
3 import { getVideoLikeActivityPubUrl } from '../url'
4 import { sendVideoRelatedActivity } from './utils'
5 import { audiencify, getAudience } from '../audience'
6 import { logger } from '../../../helpers/logger'
7 import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../typings/models'
8
9 function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
10 logger.info('Creating job to like %s.', video.url)
11
12 const activityBuilder = (audience: ActivityAudience) => {
13 const url = getVideoLikeActivityPubUrl(byActor, video)
14
15 return buildLikeActivity(url, byActor, video, audience)
16 }
17
18 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t })
19 }
20
21 function buildLikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityLike {
22 if (!audience) audience = getAudience(byActor)
23
24 return audiencify(
25 {
26 id: url,
27 type: 'Like' as 'Like',
28 actor: byActor.url,
29 object: video.url
30 },
31 audience
32 )
33 }
34
35 // ---------------------------------------------------------------------------
36
37 export {
38 sendLike,
39 buildLikeActivity
40 }