]>
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' | |
0032ebe9 | 8 | |
07197db4 | 9 | async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) { |
50d6de9c | 10 | const url = getVideoLikeActivityPubUrl(byActor, video) |
0032ebe9 | 11 | |
50d6de9c | 12 | const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
0032ebe9 | 13 | |
07197db4 C |
14 | // Send to origin |
15 | if (video.isOwned() === false) { | |
e251f170 | 16 | const audience = getVideoAudience(video, accountsInvolvedInVideo) |
2186386c | 17 | const data = likeActivityData(url, byActor, video, audience) |
0032ebe9 | 18 | |
07197db4 C |
19 | return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) |
20 | } | |
0032ebe9 | 21 | |
07197db4 | 22 | // Send to followers |
4e50b6a1 | 23 | const audience = getObjectFollowersAudience(accountsInvolvedInVideo) |
2186386c | 24 | const data = likeActivityData(url, byActor, video, audience) |
0032ebe9 | 25 | |
50d6de9c C |
26 | const followersException = [ byActor ] |
27 | return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException) | |
0032ebe9 C |
28 | } |
29 | ||
2186386c C |
30 | function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike { |
31 | if (!audience) audience = getAudience(byActor) | |
32 | ||
33 | return audiencify( | |
34 | { | |
35 | type: 'Like' as 'Like', | |
36 | id: url, | |
37 | actor: byActor.url, | |
38 | object: video.url | |
39 | }, | |
40 | audience | |
41 | ) | |
0032ebe9 C |
42 | } |
43 | ||
44 | // --------------------------------------------------------------------------- | |
45 | ||
46 | export { | |
07197db4 | 47 | sendLike, |
0032ebe9 C |
48 | likeActivityData |
49 | } |