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