]>
Commit | Line | Data |
---|---|---|
54141398 | 1 | import { Transaction } from 'sequelize' |
e71bcc0f | 2 | import { ActivityAdd } from '../../../../shared/index' |
3fd3ab2d C |
3 | import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' |
4 | import { AccountModel } from '../../../models/account/account' | |
5 | import { VideoModel } from '../../../models/video/video' | |
6 | import { VideoChannelModel } from '../../../models/video/video-channel' | |
e71bcc0f | 7 | import { getAnnounceActivityPubUrl } from '../url' |
4e50b6a1 C |
8 | import { |
9 | broadcastToFollowers, | |
10 | getAccountsInvolvedInVideo, | |
11 | getAccountsInvolvedInVideoChannel, | |
12 | getAudience, | |
13 | getObjectFollowersAudience, | |
14 | getOriginVideoAudience, | |
15 | getOriginVideoChannelAudience, | |
16 | unicastTo | |
17 | } from './misc' | |
54141398 C |
18 | import { addActivityData } from './send-add' |
19 | import { createActivityData } from './send-create' | |
54141398 | 20 | |
3fd3ab2d | 21 | async function buildVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
54141398 C |
22 | const url = getAnnounceActivityPubUrl(video.url, byAccount) |
23 | ||
24 | const videoChannel = video.VideoChannel | |
25ed141c | 25 | const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t) |
54141398 | 26 | |
25ed141c | 27 | const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) |
4e50b6a1 | 28 | const audience = getObjectFollowersAudience(accountsToForwardView) |
3fd3ab2d | 29 | return announceActivityData(url, byAccount, announcedActivity, t, audience) |
4e50b6a1 C |
30 | } |
31 | ||
3fd3ab2d | 32 | async function sendVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
4e50b6a1 C |
33 | const data = await buildVideoAnnounceToFollowers(byAccount, video, t) |
34 | ||
54141398 C |
35 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
36 | } | |
37 | ||
3fd3ab2d | 38 | async function sendVideoAnnounceToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
4e50b6a1 C |
39 | const url = getAnnounceActivityPubUrl(video.url, byAccount) |
40 | ||
41 | const videoChannel = video.VideoChannel | |
25ed141c | 42 | const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t) |
4e50b6a1 | 43 | |
25ed141c | 44 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) |
4e50b6a1 | 45 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) |
25ed141c | 46 | const data = await createActivityData(url, byAccount, announcedActivity, t, audience) |
4e50b6a1 C |
47 | |
48 | return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) | |
49 | } | |
50 | ||
3fd3ab2d | 51 | async function buildVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { |
54141398 | 52 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) |
25ed141c | 53 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) |
54141398 | 54 | |
25ed141c | 55 | const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t) |
4e50b6a1 | 56 | const audience = getObjectFollowersAudience(accountsToForwardView) |
3fd3ab2d | 57 | return announceActivityData(url, byAccount, announcedActivity, t, audience) |
4e50b6a1 C |
58 | } |
59 | ||
3fd3ab2d | 60 | async function sendVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { |
4e50b6a1 C |
61 | const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t) |
62 | ||
54141398 C |
63 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
64 | } | |
65 | ||
3fd3ab2d | 66 | async function sendVideoChannelAnnounceToOrigin (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { |
4e50b6a1 | 67 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) |
25ed141c | 68 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) |
4e50b6a1 | 69 | |
25ed141c | 70 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel, t) |
4e50b6a1 | 71 | const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo) |
25ed141c | 72 | const data = await createActivityData(url, byAccount, announcedActivity, t, audience) |
4e50b6a1 C |
73 | |
74 | return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) | |
75 | } | |
76 | ||
77 | async function announceActivityData ( | |
78 | url: string, | |
3fd3ab2d | 79 | byAccount: AccountModel, |
4e50b6a1 | 80 | object: ActivityCreate | ActivityAdd, |
25ed141c | 81 | t: Transaction, |
4e50b6a1 | 82 | audience?: ActivityAudience |
3fd3ab2d | 83 | ): Promise<ActivityAnnounce> { |
4e50b6a1 | 84 | if (!audience) { |
25ed141c | 85 | audience = await getAudience(byAccount, t) |
4e50b6a1 C |
86 | } |
87 | ||
3fd3ab2d | 88 | return { |
54141398 | 89 | type: 'Announce', |
4e50b6a1 C |
90 | to: audience.to, |
91 | cc: audience.cc, | |
54141398 C |
92 | id: url, |
93 | actor: byAccount.url, | |
94 | object | |
95 | } | |
54141398 | 96 | } |
e71bcc0f C |
97 | |
98 | // --------------------------------------------------------------------------- | |
99 | ||
100 | export { | |
4e50b6a1 C |
101 | sendVideoAnnounceToFollowers, |
102 | sendVideoChannelAnnounceToFollowers, | |
103 | sendVideoAnnounceToOrigin, | |
104 | sendVideoChannelAnnounceToOrigin, | |
105 | announceActivityData, | |
106 | buildVideoAnnounceToFollowers, | |
107 | buildVideoChannelAnnounceToFollowers | |
e71bcc0f | 108 | } |