diff options
Diffstat (limited to 'server/lib/activitypub/send-request.ts')
-rw-r--r-- | server/lib/activitypub/send-request.ts | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts index 8d013fa87..68a631a36 100644 --- a/server/lib/activitypub/send-request.ts +++ b/server/lib/activitypub/send-request.ts | |||
@@ -13,6 +13,8 @@ import { database as db } from '../../initializers' | |||
13 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../models' | 13 | import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../models' |
14 | import { VideoAbuseInstance } from '../../models/video/video-abuse-interface' | 14 | import { VideoAbuseInstance } from '../../models/video/video-abuse-interface' |
15 | import { activitypubHttpJobScheduler } from '../jobs' | 15 | import { activitypubHttpJobScheduler } from '../jobs' |
16 | import { ACTIVITY_PUB } from '../../initializers/constants' | ||
17 | import { VideoPrivacy } from '../../../shared/models/videos/video-privacy.enum' | ||
16 | 18 | ||
17 | async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { | 19 | async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) { |
18 | const byAccount = videoChannel.Account | 20 | const byAccount = videoChannel.Account |
@@ -50,7 +52,7 @@ async function sendAddVideo (video: VideoInstance, t: Transaction) { | |||
50 | const byAccount = video.VideoChannel.Account | 52 | const byAccount = video.VideoChannel.Account |
51 | 53 | ||
52 | const videoObject = video.toActivityPubObject() | 54 | const videoObject = video.toActivityPubObject() |
53 | const data = await addActivityData(video.url, byAccount, video.VideoChannel.url, videoObject) | 55 | const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject) |
54 | 56 | ||
55 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 57 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
56 | } | 58 | } |
@@ -96,7 +98,7 @@ async function sendVideoAnnounce (byAccount: AccountInstance, video: VideoInstan | |||
96 | const url = getActivityPubUrl('video', video.uuid) + '#announce' | 98 | const url = getActivityPubUrl('video', video.uuid) + '#announce' |
97 | 99 | ||
98 | const videoChannel = video.VideoChannel | 100 | const videoChannel = video.VideoChannel |
99 | const announcedActivity = await addActivityData(url, videoChannel.Account, videoChannel.url, video.toActivityPubObject()) | 101 | const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject()) |
100 | 102 | ||
101 | const data = await announceActivityData(url, byAccount, announcedActivity) | 103 | const data = await announceActivityData(url, byAccount, announcedActivity) |
102 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) | 104 | return broadcastToFollowers(data, byAccount, [ byAccount ], t) |
@@ -167,19 +169,32 @@ async function unicastTo (data: any, byAccount: AccountInstance, toAccountUrl: s | |||
167 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload) | 169 | return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload) |
168 | } | 170 | } |
169 | 171 | ||
170 | async function getPublicActivityTo (account: AccountInstance) { | 172 | async function getAudience (accountSender: AccountInstance, isPublic = true) { |
171 | const inboxUrls = await account.getFollowerSharedInboxUrls() | 173 | const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls() |
172 | 174 | ||
173 | return inboxUrls.concat('https://www.w3.org/ns/activitystreams#Public') | 175 | // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47 |
176 | let to = [] | ||
177 | let cc = [] | ||
178 | |||
179 | if (isPublic) { | ||
180 | to = [ ACTIVITY_PUB.PUBLIC ] | ||
181 | cc = followerInboxUrls | ||
182 | } else { // Unlisted | ||
183 | to = followerInboxUrls | ||
184 | cc = [ ACTIVITY_PUB.PUBLIC ] | ||
185 | } | ||
186 | |||
187 | return { to, cc } | ||
174 | } | 188 | } |
175 | 189 | ||
176 | async function createActivityData (url: string, byAccount: AccountInstance, object: any) { | 190 | async function createActivityData (url: string, byAccount: AccountInstance, object: any) { |
177 | const to = await getPublicActivityTo(byAccount) | 191 | const { to, cc } = await getAudience(byAccount) |
178 | const activity: ActivityCreate = { | 192 | const activity: ActivityCreate = { |
179 | type: 'Create', | 193 | type: 'Create', |
180 | id: url, | 194 | id: url, |
181 | actor: byAccount.url, | 195 | actor: byAccount.url, |
182 | to, | 196 | to, |
197 | cc, | ||
183 | object | 198 | object |
184 | } | 199 | } |
185 | 200 | ||
@@ -187,12 +202,13 @@ async function createActivityData (url: string, byAccount: AccountInstance, obje | |||
187 | } | 202 | } |
188 | 203 | ||
189 | async function updateActivityData (url: string, byAccount: AccountInstance, object: any) { | 204 | async function updateActivityData (url: string, byAccount: AccountInstance, object: any) { |
190 | const to = await getPublicActivityTo(byAccount) | 205 | const { to, cc } = await getAudience(byAccount) |
191 | const activity: ActivityUpdate = { | 206 | const activity: ActivityUpdate = { |
192 | type: 'Update', | 207 | type: 'Update', |
193 | id: url, | 208 | id: url, |
194 | actor: byAccount.url, | 209 | actor: byAccount.url, |
195 | to, | 210 | to, |
211 | cc, | ||
196 | object | 212 | object |
197 | } | 213 | } |
198 | 214 | ||
@@ -209,13 +225,16 @@ async function deleteActivityData (url: string, byAccount: AccountInstance) { | |||
209 | return activity | 225 | return activity |
210 | } | 226 | } |
211 | 227 | ||
212 | async function addActivityData (url: string, byAccount: AccountInstance, target: string, object: any) { | 228 | async function addActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, target: string, object: any) { |
213 | const to = await getPublicActivityTo(byAccount) | 229 | const videoPublic = video.privacy === VideoPrivacy.PUBLIC |
230 | |||
231 | const { to, cc } = await getAudience(byAccount, videoPublic) | ||
214 | const activity: ActivityAdd = { | 232 | const activity: ActivityAdd = { |
215 | type: 'Add', | 233 | type: 'Add', |
216 | id: url, | 234 | id: url, |
217 | actor: byAccount.url, | 235 | actor: byAccount.url, |
218 | to, | 236 | to, |
237 | cc, | ||
219 | object, | 238 | object, |
220 | target | 239 | target |
221 | } | 240 | } |