]>
Commit | Line | Data |
---|---|---|
0032ebe9 C |
1 | import { Transaction } from 'sequelize' |
2 | import { ActivityLike } from '../../../../shared/models/activitypub/activity' | |
0032ebe9 C |
3 | import { AccountInstance, VideoInstance } from '../../../models' |
4 | import { getVideoLikeActivityPubUrl } from '../url' | |
5 | import { | |
6 | broadcastToFollowers, | |
63c93323 | 7 | getAccountsInvolvedInVideo, |
0032ebe9 C |
8 | getAudience, |
9 | getOriginVideoAudience, | |
10 | getVideoFollowersAudience, | |
11 | unicastTo | |
12 | } from './misc' | |
13 | ||
14 | async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
15 | const url = getVideoLikeActivityPubUrl(byAccount, video) | |
16 | ||
63c93323 C |
17 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) |
18 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | |
0032ebe9 C |
19 | const data = await likeActivityData(url, byAccount, video, audience) |
20 | ||
21 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | |
22 | } | |
23 | ||
24 | async function sendLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
25 | const url = getVideoLikeActivityPubUrl(byAccount, video) | |
26 | ||
63c93323 C |
27 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) |
28 | const audience = getVideoFollowersAudience(accountsInvolvedInVideo) | |
0032ebe9 C |
29 | const data = await likeActivityData(url, byAccount, video, audience) |
30 | ||
63c93323 | 31 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video) |
0032ebe9 C |
32 | |
33 | const followersException = [ byAccount ] | |
63c93323 | 34 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) |
0032ebe9 C |
35 | } |
36 | ||
37 | async function likeActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, audience?: { to: string[], cc: string[] }) { | |
38 | if (!audience) { | |
39 | audience = await getAudience(byAccount) | |
40 | } | |
41 | ||
42 | const activity: ActivityLike = { | |
43 | type: 'Like', | |
44 | id: url, | |
45 | actor: byAccount.url, | |
46 | to: audience.to, | |
47 | cc: audience.cc, | |
48 | object: video.url | |
49 | } | |
50 | ||
51 | return activity | |
52 | } | |
53 | ||
54 | // --------------------------------------------------------------------------- | |
55 | ||
56 | export { | |
57 | sendLikeToOrigin, | |
58 | sendLikeToVideoFollowers, | |
59 | likeActivityData | |
60 | } |