]>
Commit | Line | Data |
---|---|---|
0032ebe9 | 1 | import { Transaction } from 'sequelize' |
25ed141c | 2 | import { ActivityAudience, 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, | |
4e50b6a1 | 10 | getObjectFollowersAudience, |
0032ebe9 C |
11 | unicastTo |
12 | } from './misc' | |
13 | ||
14 | async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
15 | const url = getVideoLikeActivityPubUrl(byAccount, video) | |
16 | ||
25ed141c | 17 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) |
63c93323 | 18 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) |
25ed141c | 19 | const data = await likeActivityData(url, byAccount, video, t, audience) |
0032ebe9 C |
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 | ||
25ed141c | 27 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) |
4e50b6a1 | 28 | const audience = getObjectFollowersAudience(accountsInvolvedInVideo) |
25ed141c | 29 | const data = await likeActivityData(url, byAccount, video, t, audience) |
0032ebe9 C |
30 | |
31 | const followersException = [ byAccount ] | |
25ed141c | 32 | return broadcastToFollowers(data, byAccount, accountsInvolvedInVideo, t, followersException) |
0032ebe9 C |
33 | } |
34 | ||
25ed141c C |
35 | async function likeActivityData ( |
36 | url: string, | |
37 | byAccount: AccountInstance, | |
38 | video: VideoInstance, | |
39 | t: Transaction, | |
40 | audience?: ActivityAudience | |
41 | ) { | |
0032ebe9 | 42 | if (!audience) { |
25ed141c | 43 | audience = await getAudience(byAccount, t) |
0032ebe9 C |
44 | } |
45 | ||
46 | const activity: ActivityLike = { | |
47 | type: 'Like', | |
48 | id: url, | |
49 | actor: byAccount.url, | |
50 | to: audience.to, | |
51 | cc: audience.cc, | |
52 | object: video.url | |
53 | } | |
54 | ||
55 | return activity | |
56 | } | |
57 | ||
58 | // --------------------------------------------------------------------------- | |
59 | ||
60 | export { | |
61 | sendLikeToOrigin, | |
62 | sendLikeToVideoFollowers, | |
63 | likeActivityData | |
64 | } |