From ea44f375f5d3da06ca0aebfe871b9f924a26ec29 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 27 Dec 2017 10:39:31 +0100 Subject: Send video comment comments to followers/origin --- server/lib/activitypub/send/send-create.ts | 71 +++++++++++++++++++----------- 1 file changed, 46 insertions(+), 25 deletions(-) (limited to 'server/lib/activitypub/send') diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 27b03c45f..ca50460be 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts @@ -5,14 +5,10 @@ import { getServerActor } from '../../../helpers' import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' 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, unicastTo } from './misc' @@ -37,24 +33,49 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } +async function sendCreateVideoCommentToOrigin (comment: VideoCommentModel, t: Transaction) { + const byActor = comment.Account.Actor + + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(comment.Video, t) + const audience = getOriginVideoAudience(comment.Video, 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) +} + +async function sendCreateVideoCommentToVideoFollowers (comment: VideoCommentModel, t: Transaction) { + const byActor = comment.Account.Actor + + const actorsToForwardView = await getActorsInvolvedInVideo(comment.Video, t) + const audience = getObjectFollowersAudience(actorsToForwardView) + + const commentObject = comment.toActivityPubObject() + const data = await createActivityData(comment.url, byActor, commentObject, t, audience) + + const followersException = [ byActor ] + return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) +} + async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { const url = getVideoViewActivityPubUrl(byActor, video) - const viewActivity = createViewActivityData(byActor, video) + const viewActivityData = createViewActivityData(byActor, video) const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) - const data = await createActivityData(url, byActor, viewActivity, t, audience) + const data = await createActivityData(url, byActor, viewActivityData, t, audience) return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { const url = getVideoViewActivityPubUrl(byActor, video) - const viewActivity = createViewActivityData(byActor, video) + const viewActivityData = createViewActivityData(byActor, video) const actorsToForwardView = await getActorsInvolvedInVideo(video, t) const audience = getObjectFollowersAudience(actorsToForwardView) - const data = await createActivityData(url, byActor, viewActivity, t, audience) + const data = await createActivityData(url, byActor, viewActivityData, t, audience) // Use the server actor to send the view const serverActor = await getServerActor() @@ -64,22 +85,22 @@ async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: Video async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { const url = getVideoDislikeActivityPubUrl(byActor, video) - const dislikeActivity = createDislikeActivityData(byActor, video) + const dislikeActivityData = createDislikeActivityData(byActor, video) const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) - const data = await createActivityData(url, byActor, dislikeActivity, t, audience) + const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { const url = getVideoDislikeActivityPubUrl(byActor, video) - const dislikeActivity = createDislikeActivityData(byActor, video) + const dislikeActivityData = createDislikeActivityData(byActor, video) const actorsToForwardView = await getActorsInvolvedInVideo(video, t) const audience = getObjectFollowersAudience(actorsToForwardView) - const data = await createActivityData(url, byActor, dislikeActivity, t, audience) + const data = await createActivityData(url, byActor, dislikeActivityData, t, audience) const followersException = [ byActor ] return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) @@ -112,6 +133,14 @@ function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { } } +function createViewActivityData (byActor: ActorModel, video: VideoModel) { + return { + type: 'View', + actor: byActor.url, + object: video.url + } +} + // --------------------------------------------------------------------------- export { @@ -122,15 +151,7 @@ export { sendCreateViewToVideoFollowers, sendCreateDislikeToOrigin, sendCreateDislikeToVideoFollowers, - createDislikeActivityData -} - -// --------------------------------------------------------------------------- - -function createViewActivityData (byActor: ActorModel, video: VideoModel) { - return { - type: 'View', - actor: byActor.url, - object: video.url - } + createDislikeActivityData, + sendCreateVideoCommentToOrigin, + sendCreateVideoCommentToVideoFollowers } -- cgit v1.2.3