aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/send')
-rw-r--r--server/lib/activitypub/send/misc.ts47
-rw-r--r--server/lib/activitypub/send/send-create.ts40
2 files changed, 64 insertions, 23 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}
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index e2ee639d9..9db663be1 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -8,7 +8,7 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse'
8import { VideoCommentModel } from '../../../models/video/video-comment' 8import { VideoCommentModel } from '../../../models/video/video-comment'
9import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' 9import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
10import { 10import {
11 audiencify, broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, 11 audiencify, broadcastToActors, broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience,
12 getOriginVideoAudience, getOriginVideoCommentAudience, 12 getOriginVideoAudience, getOriginVideoCommentAudience,
13 unicastTo 13 unicastTo
14} from './misc' 14} from './misc'
@@ -39,11 +39,20 @@ async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Tr
39 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) 39 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t)
40 const commentObject = comment.toActivityPubObject(threadParentComments) 40 const commentObject = comment.toActivityPubObject(threadParentComments)
41 41
42 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) 42 const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t)
43 const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo) 43 actorsInvolvedInComment.push(byActor)
44 const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment)
44 45
45 const data = await createActivityData(comment.url, byActor, commentObject, t, audience) 46 const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
46 47
48 // This was a reply, send it to the parent actors
49 const actorsException = [ byActor ]
50 await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), t, actorsException)
51
52 // Broadcast to our followers
53 await broadcastToFollowers(data, byActor, [ byActor ], t)
54
55 // Send to origin
47 return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl, t) 56 return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl, t)
48} 57}
49 58
@@ -52,12 +61,21 @@ async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentMode
52 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) 61 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t)
53 const commentObject = comment.toActivityPubObject(threadParentComments) 62 const commentObject = comment.toActivityPubObject(threadParentComments)
54 63
55 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) 64 const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t)
56 const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo) 65 actorsInvolvedInComment.push(byActor)
66
67 const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment)
57 const data = await createActivityData(comment.url, byActor, commentObject, t, audience) 68 const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
58 69
59 const followersException = [ byActor ] 70 // This was a reply, send it to the parent actors
60 return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) 71 const actorsException = [ byActor ]
72 await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), t, actorsException)
73
74 // Broadcast to our followers
75 await broadcastToFollowers(data, byActor, [ byActor ], t)
76
77 // Send to actors involved in the comment
78 return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
61} 79}
62 80
63async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 81async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
@@ -81,8 +99,8 @@ async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: Video
81 99
82 // Use the server actor to send the view 100 // Use the server actor to send the view
83 const serverActor = await getServerActor() 101 const serverActor = await getServerActor()
84 const followersException = [ byActor ] 102 const actorsException = [ byActor ]
85 return broadcastToFollowers(data, serverActor, actorsToForwardView, t, followersException) 103 return broadcastToFollowers(data, serverActor, actorsToForwardView, t, actorsException)
86} 104}
87 105
88async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 106async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
@@ -104,8 +122,8 @@ async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: Vi
104 const audience = getObjectFollowersAudience(actorsToForwardView) 122 const audience = getObjectFollowersAudience(actorsToForwardView)
105 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) 123 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
106 124
107 const followersException = [ byActor ] 125 const actorsException = [ byActor ]
108 return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) 126 return broadcastToFollowers(data, byActor, actorsToForwardView, t, actorsException)
109} 127}
110 128
111async function createActivityData ( 129async function createActivityData (