]>
Commit | Line | Data |
---|---|---|
0032ebe9 | 1 | import { Transaction } from 'sequelize' |
3fd3ab2d | 2 | import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' |
50d6de9c | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
3fd3ab2d | 4 | import { VideoModel } from '../../../models/video/video' |
0032ebe9 | 5 | import { getVideoLikeActivityPubUrl } from '../url' |
e251f170 C |
6 | import { broadcastToFollowers, unicastTo } from './utils' |
7 | import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience' | |
8e0fd45e | 8 | import { logger } from '../../../helpers/logger' |
0032ebe9 | 9 | |
07197db4 | 10 | async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) { |
8e0fd45e C |
11 | logger.info('Creating job to like %s.', video.url) |
12 | ||
50d6de9c | 13 | const url = getVideoLikeActivityPubUrl(byActor, video) |
0032ebe9 | 14 | |
50d6de9c | 15 | const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
0032ebe9 | 16 | |
07197db4 C |
17 | // Send to origin |
18 | if (video.isOwned() === false) { | |
e251f170 | 19 | const audience = getVideoAudience(video, accountsInvolvedInVideo) |
2186386c | 20 | const data = likeActivityData(url, byActor, video, audience) |
0032ebe9 | 21 | |
07197db4 C |
22 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
23 | } | |
0032ebe9 | 24 | |
07197db4 | 25 | // Send to followers |
4e50b6a1 | 26 | const audience = getObjectFollowersAudience(accountsInvolvedInVideo) |
2186386c | 27 | const data = likeActivityData(url, byActor, video, audience) |
0032ebe9 | 28 | |
50d6de9c C |
29 | const followersException = [ byActor ] |
30 | return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException) | |
0032ebe9 C |
31 | } |
32 | ||
2186386c C |
33 | function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike { |
34 | if (!audience) audience = getAudience(byActor) | |
35 | ||
36 | return audiencify( | |
37 | { | |
38 | type: 'Like' as 'Like', | |
39 | id: url, | |
40 | actor: byActor.url, | |
41 | object: video.url | |
42 | }, | |
43 | audience | |
44 | ) | |
0032ebe9 C |
45 | } |
46 | ||
47 | // --------------------------------------------------------------------------- | |
48 | ||
49 | export { | |
07197db4 | 50 | sendLike, |
0032ebe9 C |
51 | likeActivityData |
52 | } |