]>
Commit | Line | Data |
---|---|---|
0032ebe9 | 1 | import { Transaction } from 'sequelize' |
3fd3ab2d | 2 | import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' |
de94ac86 | 3 | import { getVideoLikeActivityPubUrlByLocalActor } from '../url' |
a2377d15 C |
4 | import { sendVideoRelatedActivity } from './utils' |
5 | import { audiencify, getAudience } from '../audience' | |
8e0fd45e | 6 | import { logger } from '../../../helpers/logger' |
26d6bf65 | 7 | import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models' |
0032ebe9 | 8 | |
a1587156 | 9 | function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { |
8e0fd45e C |
10 | logger.info('Creating job to like %s.', video.url) |
11 | ||
a2377d15 | 12 | const activityBuilder = (audience: ActivityAudience) => { |
de94ac86 | 13 | const url = getVideoLikeActivityPubUrlByLocalActor(byActor, video) |
0032ebe9 | 14 | |
a2377d15 | 15 | return buildLikeActivity(url, byActor, video, audience) |
07197db4 | 16 | } |
0032ebe9 | 17 | |
a2377d15 | 18 | return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t }) |
0032ebe9 C |
19 | } |
20 | ||
453e83ea | 21 | function buildLikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityLike { |
2186386c C |
22 | if (!audience) audience = getAudience(byActor) |
23 | ||
24 | return audiencify( | |
25 | { | |
2186386c | 26 | id: url, |
5c6d985f | 27 | type: 'Like' as 'Like', |
2186386c C |
28 | actor: byActor.url, |
29 | object: video.url | |
30 | }, | |
31 | audience | |
32 | ) | |
0032ebe9 C |
33 | } |
34 | ||
35 | // --------------------------------------------------------------------------- | |
36 | ||
37 | export { | |
07197db4 | 38 | sendLike, |
c48e82b5 | 39 | buildLikeActivity |
0032ebe9 | 40 | } |