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