+async function sendCreateVideoComment (comment: MCommentOwnerVideo, transaction: Transaction) {
+ logger.info('Creating job to send comment %s.', comment.url)
+
+ const isOrigin = comment.Video.isOwned()
+
+ const byActor = comment.Account.Actor
+ const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, transaction)
+ const commentObject = comment.toActivityPubObject(threadParentComments)
+
+ const actorsInvolvedInComment = await getActorsInvolvedInVideo(comment.Video, transaction)
+ // Add the actor that commented too
+ actorsInvolvedInComment.push(byActor)
+
+ const parentsCommentActors = threadParentComments.filter(c => !c.isDeleted())
+ .map(c => c.Account.Actor)
+
+ let audience: ActivityAudience
+ if (isOrigin) {
+ audience = getVideoCommentAudience(comment, threadParentComments, actorsInvolvedInComment, isOrigin)
+ } else {
+ audience = getAudienceFromFollowersOf(actorsInvolvedInComment.concat(parentsCommentActors))
+ }
+
+ const createActivity = buildCreateActivity(comment.url, byActor, commentObject, audience)
+
+ // This was a reply, send it to the parent actors
+ const actorsException = [ byActor ]
+ await broadcastToActors({
+ data: createActivity,
+ byActor,
+ toActors: parentsCommentActors,
+ transaction,
+ actorsException,
+ contextType: 'Comment'
+ })
+
+ // Broadcast to our followers
+ await broadcastToFollowers({
+ data: createActivity,
+ byActor,
+ toFollowersOf: [ byActor ],
+ transaction,
+ contextType: 'Comment'
+ })
+
+ // Send to actors involved in the comment
+ if (isOrigin) {
+ return broadcastToFollowers({
+ data: createActivity,
+ byActor,
+ toFollowersOf: actorsInvolvedInComment,
+ transaction,
+ actorsException,
+ contextType: 'Comment'
+ })