diff options
Diffstat (limited to 'server/lib/activitypub/send/send-announce.ts')
-rw-r--r-- | server/lib/activitypub/send/send-announce.ts | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts index 3acf604cd..e685323e8 100644 --- a/server/lib/activitypub/send/send-announce.ts +++ b/server/lib/activitypub/send/send-announce.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityAdd } from '../../../../shared/index' | 2 | import { ActivityAdd } from '../../../../shared/index' |
3 | import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub/activity' | 3 | import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' |
4 | import { AccountInstance, VideoInstance } from '../../../models' | 4 | import { AccountModel } from '../../../models/account/account' |
5 | import { VideoChannelInstance } from '../../../models/video/video-channel-interface' | 5 | import { VideoModel } from '../../../models/video/video' |
6 | import { VideoChannelModel } from '../../../models/video/video-channel' | ||
6 | import { getAnnounceActivityPubUrl } from '../url' | 7 | import { getAnnounceActivityPubUrl } from '../url' |
7 | import { | 8 | import { |
8 | broadcastToFollowers, | 9 | broadcastToFollowers, |
@@ -17,7 +18,7 @@ import { | |||
17 | import { addActivityData } from './send-add' | 18 | import { addActivityData } from './send-add' |
18 | import { createActivityData } from './send-create' | 19 | import { createActivityData } from './send-create' |
19 | 20 | ||
20 | async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 21 | async function buildVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
21 | const url = getAnnounceActivityPubUrl(video.url, byAccount) | 22 | const url = getAnnounceActivityPubUrl(video.url, byAccount) |
22 | 23 | ||
23 | const videoChannel = video.VideoChannel | 24 | const videoChannel = video.VideoChannel |
@@ -25,18 +26,16 @@ async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video: | |||
25 | 26 | ||
26 | const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) | 27 | const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) |
27 | const audience = getObjectFollowersAudience(accountsToForwardView) | 28 | const audience = getObjectFollowersAudience(accountsToForwardView) |
28 | const data = await announceActivityData(url, byAccount, announcedActivity, t, audience) | 29 | return announceActivityData(url, byAccount, announcedActivity, t, audience) |
29 | |||
30 | return data | ||
31 | } | 30 | } |
32 | 31 | ||
33 | async function sendVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 32 | async function sendVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
34 | const data = await buildVideoAnnounceToFollowers(byAccount, video, t) | 33 | const data = await buildVideoAnnounceToFollowers(byAccount, video, t) |
35 | 34 | ||
36 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 35 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
37 | } | 36 | } |
38 | 37 | ||
39 | async function sendVideoAnnounceToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 38 | async function sendVideoAnnounceToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { |
40 | const url = getAnnounceActivityPubUrl(video.url, byAccount) | 39 | const url = getAnnounceActivityPubUrl(video.url, byAccount) |
41 | 40 | ||
42 | const videoChannel = video.VideoChannel | 41 | const videoChannel = video.VideoChannel |
@@ -49,24 +48,22 @@ async function sendVideoAnnounceToOrigin (byAccount: AccountInstance, video: Vid | |||
49 | return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) | 48 | return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) |
50 | } | 49 | } |
51 | 50 | ||
52 | async function buildVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { | 51 | async function buildVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { |
53 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) | 52 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) |
54 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) | 53 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) |
55 | 54 | ||
56 | const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t) | 55 | const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t) |
57 | const audience = getObjectFollowersAudience(accountsToForwardView) | 56 | const audience = getObjectFollowersAudience(accountsToForwardView) |
58 | const data = await announceActivityData(url, byAccount, announcedActivity, t, audience) | 57 | return announceActivityData(url, byAccount, announcedActivity, t, audience) |
59 | |||
60 | return data | ||
61 | } | 58 | } |
62 | 59 | ||
63 | async function sendVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { | 60 | async function sendVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { |
64 | const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t) | 61 | const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t) |
65 | 62 | ||
66 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 63 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
67 | } | 64 | } |
68 | 65 | ||
69 | async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) { | 66 | async function sendVideoChannelAnnounceToOrigin (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { |
70 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) | 67 | const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) |
71 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) | 68 | const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) |
72 | 69 | ||
@@ -79,16 +76,16 @@ async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, vid | |||
79 | 76 | ||
80 | async function announceActivityData ( | 77 | async function announceActivityData ( |
81 | url: string, | 78 | url: string, |
82 | byAccount: AccountInstance, | 79 | byAccount: AccountModel, |
83 | object: ActivityCreate | ActivityAdd, | 80 | object: ActivityCreate | ActivityAdd, |
84 | t: Transaction, | 81 | t: Transaction, |
85 | audience?: ActivityAudience | 82 | audience?: ActivityAudience |
86 | ) { | 83 | ): Promise<ActivityAnnounce> { |
87 | if (!audience) { | 84 | if (!audience) { |
88 | audience = await getAudience(byAccount, t) | 85 | audience = await getAudience(byAccount, t) |
89 | } | 86 | } |
90 | 87 | ||
91 | const activity: ActivityAnnounce = { | 88 | return { |
92 | type: 'Announce', | 89 | type: 'Announce', |
93 | to: audience.to, | 90 | to: audience.to, |
94 | cc: audience.cc, | 91 | cc: audience.cc, |
@@ -96,8 +93,6 @@ async function announceActivityData ( | |||
96 | actor: byAccount.url, | 93 | actor: byAccount.url, |
97 | object | 94 | object |
98 | } | 95 | } |
99 | |||
100 | return activity | ||
101 | } | 96 | } |
102 | 97 | ||
103 | // --------------------------------------------------------------------------- | 98 | // --------------------------------------------------------------------------- |