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/process/process-create.ts | 36 +++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'server/lib/activitypub/process') diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 6c2ee97eb..628942a58 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts @@ -257,11 +257,11 @@ function createVideoComment (byActor: ActorModel, activity: ActivityCreate) { if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) return sequelizeTypescript.transaction(async t => { - const video = await VideoModel.loadByUrl(comment.inReplyTo, t) + let video = await VideoModel.loadByUrl(comment.inReplyTo, t) // This is a new thread if (video) { - return VideoCommentModel.create({ + await VideoCommentModel.create({ url: comment.id, text: comment.content, originCommentId: null, @@ -269,19 +269,27 @@ function createVideoComment (byActor: ActorModel, activity: ActivityCreate) { videoId: video.id, accountId: byAccount.id }, { transaction: t }) - } + } else { + const inReplyToComment = await VideoCommentModel.loadByUrl(comment.inReplyTo, t) + if (!inReplyToComment) throw new Error('Unknown replied comment ' + comment.inReplyTo) - const inReplyToComment = await VideoCommentModel.loadByUrl(comment.inReplyTo, t) - if (!inReplyToComment) throw new Error('Unknown replied comment ' + comment.inReplyTo) + video = await VideoModel.load(inReplyToComment.videoId) - const originCommentId = inReplyToComment.originCommentId || inReplyToComment.id - return VideoCommentModel.create({ - url: comment.id, - text: comment.content, - originCommentId, - inReplyToCommentId: inReplyToComment.id, - videoId: inReplyToComment.videoId, - accountId: byAccount.id - }, { transaction: t }) + const originCommentId = inReplyToComment.originCommentId || inReplyToComment.id + await VideoCommentModel.create({ + url: comment.id, + text: comment.content, + originCommentId, + inReplyToCommentId: inReplyToComment.id, + videoId: video.id, + accountId: byAccount.id + }, { transaction: t }) + } + + if (video.isOwned()) { + // Don't resend the activity to the sender + const exceptions = [ byActor ] + await forwardActivity(activity, t, exceptions) + } }) } -- cgit v1.2.3