aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/misc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/send/misc.ts')
-rw-r--r--server/lib/activitypub/send/misc.ts47
1 files changed, 35 insertions, 12 deletions
diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts
index 4aa514c15..2a9f4cae8 100644
--- a/server/lib/activitypub/send/misc.ts
+++ b/server/lib/activitypub/send/misc.ts
@@ -12,12 +12,13 @@ import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../../jobs/
12async function forwardActivity ( 12async function forwardActivity (
13 activity: Activity, 13 activity: Activity,
14 t: Transaction, 14 t: Transaction,
15 followersException: ActorModel[] = [] 15 followersException: ActorModel[] = [],
16 additionalFollowerUrls: string[] = []
16) { 17) {
17 const to = activity.to || [] 18 const to = activity.to || []
18 const cc = activity.cc || [] 19 const cc = activity.cc || []
19 20
20 const followersUrls: string[] = [] 21 const followersUrls = additionalFollowerUrls
21 for (const dest of to.concat(cc)) { 22 for (const dest of to.concat(cc)) {
22 if (dest.endsWith('/followers')) { 23 if (dest.endsWith('/followers')) {
23 followersUrls.push(dest) 24 followersUrls.push(dest)
@@ -47,13 +48,25 @@ async function broadcastToFollowers (
47 byActor: ActorModel, 48 byActor: ActorModel,
48 toActorFollowers: ActorModel[], 49 toActorFollowers: ActorModel[],
49 t: Transaction, 50 t: Transaction,
50 followersException: ActorModel[] = [] 51 actorsException: ActorModel[] = []
51) { 52) {
52 const uris = await computeFollowerUris(toActorFollowers, followersException, t) 53 const uris = await computeFollowerUris(toActorFollowers, actorsException, t)
53 if (uris.length === 0) { 54 return broadcastTo(uris, data, byActor, t)
54 logger.info('0 followers for %s, no broadcasting.', toActorFollowers.map(a => a.id).join(', ')) 55}
55 return undefined 56
56 } 57async function broadcastToActors (
58 data: any,
59 byActor: ActorModel,
60 toActors: ActorModel[],
61 t: Transaction,
62 actorsException: ActorModel[] = []
63) {
64 const uris = await computeUris(toActors, actorsException)
65 return broadcastTo(uris, data, byActor, t)
66}
67
68async function broadcastTo (uris: string[], data: any, byActor: ActorModel, t: Transaction) {
69 if (uris.length === 0) return undefined
57 70
58 logger.debug('Creating broadcast job.', { uris }) 71 logger.debug('Creating broadcast job.', { uris })
59 72
@@ -149,12 +162,20 @@ function audiencify (object: any, audience: ActivityAudience) {
149 return Object.assign(object, audience) 162 return Object.assign(object, audience)
150} 163}
151 164
152async function computeFollowerUris (toActorFollower: ActorModel[], followersException: ActorModel[], t: Transaction) { 165async function computeFollowerUris (toActorFollower: ActorModel[], actorsException: ActorModel[], t: Transaction) {
153 const toActorFollowerIds = toActorFollower.map(a => a.id) 166 const toActorFollowerIds = toActorFollower.map(a => a.id)
154 167
155 const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t) 168 const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t)
156 const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl) 169 const sharedInboxesException = actorsException.map(f => f.sharedInboxUrl)
157 return result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1) 170 return result.data.filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1)
171}
172
173async function computeUris (toActors: ActorModel[], actorsException: ActorModel[] = []) {
174 const toActorSharedInboxesSet = new Set(toActors.map(a => a.sharedInboxUrl))
175
176 const sharedInboxesException = actorsException.map(f => f.sharedInboxUrl)
177 return Array.from(toActorSharedInboxesSet)
178 .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1)
158} 179}
159 180
160// --------------------------------------------------------------------------- 181// ---------------------------------------------------------------------------
@@ -168,5 +189,7 @@ export {
168 getObjectFollowersAudience, 189 getObjectFollowersAudience,
169 forwardActivity, 190 forwardActivity,
170 audiencify, 191 audiencify,
171 getOriginVideoCommentAudience 192 getOriginVideoCommentAudience,
193 computeUris,
194 broadcastToActors
172} 195}