]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/send/send-create.ts
Fix announce activities
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-create.ts
index e2ee639d9cea3e378ebbda95d1b3e4081c31138e..b92615e9bc89cea7b6b74af8da7d9ab41a05c38b 100644 (file)
@@ -8,8 +8,14 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse'
 import { VideoCommentModel } from '../../../models/video/video-comment'
 import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
 import {
-  audiencify, broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience,
-  getOriginVideoAudience, getOriginVideoCommentAudience,
+  audiencify,
+  broadcastToActors,
+  broadcastToFollowers,
+  getActorsInvolvedInVideo,
+  getAudience,
+  getObjectFollowersAudience,
+  getOriginVideoAudience,
+  getOriginVideoCommentAudience,
   unicastTo
 } from './misc'
 
@@ -31,7 +37,7 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel,
   const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
   const data = await createActivityData(url, byActor, videoAbuse.toActivityPubObject(), t, audience)
 
-  return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
+  return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
 }
 
 async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) {
@@ -39,12 +45,21 @@ async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Tr
   const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t)
   const commentObject = comment.toActivityPubObject(threadParentComments)
 
-  const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t)
-  const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo)
+  const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t)
+  actorsInvolvedInComment.push(byActor)
+  const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment)
 
   const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
 
-  return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl, t)
+  // This was a reply, send it to the parent actors
+  const actorsException = [ byActor ]
+  await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
+
+  // Broadcast to our followers
+  await broadcastToFollowers(data, byActor, [ byActor ], t)
+
+  // Send to origin
+  return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
 }
 
 async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) {
@@ -52,12 +67,21 @@ async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentMode
   const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t)
   const commentObject = comment.toActivityPubObject(threadParentComments)
 
-  const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t)
-  const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo)
+  const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, t)
+  actorsInvolvedInComment.push(byActor)
+
+  const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment)
   const data = await createActivityData(comment.url, byActor, commentObject, t, audience)
 
-  const followersException = [ byActor ]
-  return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
+  // This was a reply, send it to the parent actors
+  const actorsException = [ byActor ]
+  await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
+
+  // Broadcast to our followers
+  await broadcastToFollowers(data, byActor, [ byActor ], t)
+
+  // Send to actors involved in the comment
+  return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
 }
 
 async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
@@ -68,7 +92,7 @@ async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t
   const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
   const data = await createActivityData(url, byActor, viewActivityData, t, audience)
 
-  return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
+  return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
 }
 
 async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
@@ -81,8 +105,8 @@ async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: Video
 
   // Use the server actor to send the view
   const serverActor = await getServerActor()
-  const followersException = [ byActor ]
-  return broadcastToFollowers(data, serverActor, actorsToForwardView, t, followersException)
+  const actorsException = [ byActor ]
+  return broadcastToFollowers(data, serverActor, actorsToForwardView, t, actorsException)
 }
 
 async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
@@ -93,7 +117,7 @@ async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel
   const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
   const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
 
-  return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
+  return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
 }
 
 async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
@@ -104,8 +128,8 @@ async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: Vi
   const audience = getObjectFollowersAudience(actorsToForwardView)
   const data = await createActivityData(url, byActor, dislikeActivityData, t, audience)
 
-  const followersException = [ byActor ]
-  return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException)
+  const actorsException = [ byActor ]
+  return broadcastToFollowers(data, byActor, actorsToForwardView, t, actorsException)
 }
 
 async function createActivityData (