From d7e70384a360cda51fe23712331110a5c8b1124c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Jan 2018 11:19:25 +0100 Subject: Add mentions to comments --- server/lib/activitypub/send/misc.ts | 38 ++++++++++++++++++++++++++---- server/lib/activitypub/send/send-create.ts | 18 +++++++------- 2 files changed, 44 insertions(+), 12 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts index 05f327b29..4aa514c15 100644 --- a/server/lib/activitypub/send/misc.ts +++ b/server/lib/activitypub/send/misc.ts @@ -5,6 +5,7 @@ import { ACTIVITY_PUB } from '../../../initializers' import { ActorModel } from '../../../models/activitypub/actor' import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { VideoModel } from '../../../models/video/video' +import { VideoCommentModel } from '../../../models/video/video-comment' import { VideoShareModel } from '../../../models/video/video-share' import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../../jobs/activitypub-http-job-scheduler' @@ -84,6 +85,34 @@ function getOriginVideoAudience (video: VideoModel, actorsInvolvedInVideo: Actor } } +function getOriginVideoCommentAudience ( + videoComment: VideoCommentModel, + threadParentComments: VideoCommentModel[], + actorsInvolvedInVideo: ActorModel[], + isOrigin = false +) { + const to = [ ACTIVITY_PUB.PUBLIC ] + const cc = [ ] + + // Owner of the video we comment + if (isOrigin === false) { + cc.push(videoComment.Video.VideoChannel.Account.Actor.url) + } + + // Followers of the poster + cc.push(videoComment.Account.Actor.followersUrl) + + // Send to actors we reply to + for (const parentComment of threadParentComments) { + cc.push(parentComment.Account.Actor.url) + } + + return { + to, + cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl)) + } +} + function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { return { to: actorsInvolvedInObject.map(a => a.followersUrl), @@ -92,10 +121,10 @@ function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { } async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) { - const actorsToForwardView = await VideoShareModel.loadActorsByShare(video.id, t) - actorsToForwardView.push(video.VideoChannel.Account.Actor) + const actors = await VideoShareModel.loadActorsByShare(video.id, t) + actors.push(video.VideoChannel.Account.Actor) - return actorsToForwardView + return actors } async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) { @@ -138,5 +167,6 @@ export { getActorsInvolvedInVideo, getObjectFollowersAudience, forwardActivity, - audiencify + audiencify, + getOriginVideoCommentAudience } diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 2f5cdc8c5..e2ee639d9 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts @@ -8,7 +8,8 @@ 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, + audiencify, broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, + getOriginVideoAudience, getOriginVideoCommentAudience, unicastTo } from './misc' @@ -35,11 +36,12 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) { const byActor = comment.Account.Actor + const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) + const commentObject = comment.toActivityPubObject(threadParentComments) const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) - const audience = getOriginVideoAudience(comment.Video, actorsInvolvedInVideo) + const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo) - const commentObject = comment.toActivityPubObject() const data = await createActivityData(comment.url, byActor, commentObject, t, audience) return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl, t) @@ -47,15 +49,15 @@ async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Tr async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) { const byActor = comment.Account.Actor + const threadParentComments = await VideoCommentModel.listThreadParentComments(comment, t) + const commentObject = comment.toActivityPubObject(threadParentComments) - const actorsToForwardView = await getActorsInvolvedInVideo(comment.Video, t) - const audience = getObjectFollowersAudience(actorsToForwardView) - - const commentObject = comment.toActivityPubObject() + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) + const audience = getOriginVideoCommentAudience(comment, threadParentComments, actorsInvolvedInVideo) const data = await createActivityData(comment.url, byActor, commentObject, t, audience) const followersException = [ byActor ] - return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) + return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException) } async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { -- cgit v1.2.3