aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-create.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/send/send-create.ts')
-rw-r--r--server/lib/activitypub/send/send-create.ts102
1 files changed, 43 insertions, 59 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index d73dd8d24..4ff20b033 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -40,105 +40,92 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel,
40 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 40 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
41} 41}
42 42
43async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) { 43async function sendCreateVideoComment (comment: VideoCommentModel, t: Transaction) {
44 const isOrigin = comment.Video.isOwned()
45
44 const byActor = comment.Account.Actor 46 const byActor = comment.Account.Actor
45 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) 47 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t)
46 const commentObject = comment.toActivityPubObject(threadParentComments) 48 const commentObject = comment.toActivityPubObject(threadParentComments)
47 49
48 const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t) 50 const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t)
49 actorsInvolvedInComment.push(byActor) 51 actorsInvolvedInComment.push(byActor)
50 const audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment)
51
52 const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
53
54 // This was a reply, send it to the parent actors
55 const actorsException = [ byActor ]
56 await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
57
58 // Broadcast to our followers
59 await broadcastToFollowers(data, byActor, [ byActor ], t)
60 52
61 // Send to origin 53 const parentsCommentActors = threadParentComments.map(c => c.Account.Actor)
62 return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
63}
64 54
65async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) { 55 let audience: ActivityAudience
66 const byActor = comment.Account.Actor 56 if (isOrigin) {
67 const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) 57 audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, isOrigin)
68 const commentObject = comment.toActivityPubObject(threadParentComments) 58 } else {
69 59 audience = getObjectFollowersAudience(actorsInvolvedInComment.concat(parentsCommentActors))
70 const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t) 60 }
71 actorsInvolvedInComment.push(byActor)
72 61
73 const audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, true)
74 const data = await createActivityData(comment.url, byActor, commentObject, t, audience) 62 const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
75 63
76 // This was a reply, send it to the parent actors 64 // This was a reply, send it to the parent actors
77 const actorsException = [ byActor ] 65 const actorsException = [ byActor ]
78 await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException) 66 await broadcastToActors(data, byActor, parentsCommentActors, actorsException)
79 67
80 // Broadcast to our followers 68 // Broadcast to our followers
81 await broadcastToFollowers(data, byActor, [ byActor ], t) 69 await broadcastToFollowers(data, byActor, [ byActor ], t)
82 70
83 // Send to actors involved in the comment 71 // Send to actors involved in the comment
84 return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException) 72 if (isOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
73
74 // Send to origin
75 return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
85} 76}
86 77
87async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 78async function sendCreateView (byActor: ActorModel, video: VideoModel, t: Transaction) {
88 const url = getVideoViewActivityPubUrl(byActor, video) 79 const url = getVideoViewActivityPubUrl(byActor, video)
89 const viewActivityData = createViewActivityData(byActor, video) 80 const viewActivityData = createViewActivityData(byActor, video)
90 81
91 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 82 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
92 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
93 const data = await createActivityData(url, byActor, viewActivityData, t, audience)
94 83
95 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 84 // Send to origin
96} 85 if (video.isOwned() === false) {
86 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
87 const data = await createActivityData(url, byActor, viewActivityData, t, audience)
97 88
98async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 89 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
99 const url = getVideoViewActivityPubUrl(byActor, video) 90 }
100 const viewActivityData = createViewActivityData(byActor, video)
101 91
102 const actorsToForwardView = await getActorsInvolvedInVideo(video, t) 92 // Send to followers
103 const audience = getObjectFollowersAudience(actorsToForwardView) 93 const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
104 const data = await createActivityData(url, byActor, viewActivityData, t, audience) 94 const data = await createActivityData(url, byActor, viewActivityData, t, audience)
105 95
106 // Use the server actor to send the view 96 // Use the server actor to send the view
107 const serverActor = await getServerActor() 97 const serverActor = await getServerActor()
108 const actorsException = [ byActor ] 98 const actorsException = [ byActor ]
109 return broadcastToFollowers(data, serverActor, actorsToForwardView, t, actorsException) 99 return broadcastToFollowers(data, serverActor, actorsInvolvedInVideo, t, actorsException)
110} 100}
111 101
112async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { 102async function sendCreateDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
113 const url = getVideoDislikeActivityPubUrl(byActor, video) 103 const url = getVideoDislikeActivityPubUrl(byActor, video)
114 const dislikeActivityData = createDislikeActivityData(byActor, video) 104 const dislikeActivityData = createDislikeActivityData(byActor, video)
115 105
116 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 106 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
117 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
118 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
119 107
120 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 108 // Send to origin
121} 109 if (video.isOwned() === false) {
110 const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
111 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
122 112
123async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { 113 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
124 const url = getVideoDislikeActivityPubUrl(byActor, video) 114 }
125 const dislikeActivityData = createDislikeActivityData(byActor, video)
126 115
127 const actorsToForwardView = await getActorsInvolvedInVideo(video, t) 116 // Send to followers
128 const audience = getObjectFollowersAudience(actorsToForwardView) 117 const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
129 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) 118 const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
130 119
131 const actorsException = [ byActor ] 120 const actorsException = [ byActor ]
132 return broadcastToFollowers(data, byActor, actorsToForwardView, t, actorsException) 121 return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, actorsException)
133} 122}
134 123
135async function createActivityData ( 124async function createActivityData (url: string,
136 url: string, 125 byActor: ActorModel,
137 byActor: ActorModel, 126 object: any,
138 object: any, 127 t: Transaction,
139 t: Transaction, 128 audience?: ActivityAudience): Promise<ActivityCreate> {
140 audience?: ActivityAudience
141): Promise<ActivityCreate> {
142 if (!audience) { 129 if (!audience) {
143 audience = await getAudience(byActor, t) 130 audience = await getAudience(byActor, t)
144 } 131 }
@@ -173,11 +160,8 @@ export {
173 sendCreateVideo, 160 sendCreateVideo,
174 sendVideoAbuse, 161 sendVideoAbuse,
175 createActivityData, 162 createActivityData,
176 sendCreateViewToOrigin, 163 sendCreateView,
177 sendCreateViewToVideoFollowers, 164 sendCreateDislike,
178 sendCreateDislikeToOrigin,
179 sendCreateDislikeToVideoFollowers,
180 createDislikeActivityData, 165 createDislikeActivityData,
181 sendCreateVideoCommentToOrigin, 166 sendCreateVideoComment
182 sendCreateVideoCommentToVideoFollowers
183} 167}