1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

Send video comment comments to followers/origin

This commit is contained in:
Chocobozzz 2017-12-27 10:39:31 +01:00
parent e2e22e40f9
commit ea44f375f5
No known key found for this signature in database
GPG key ID: 583A612D890159BE
5 changed files with 118 additions and 51 deletions

View file

@ -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)
video = await VideoModel.load(inReplyToComment.videoId)
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 })
}
const inReplyToComment = await VideoCommentModel.loadByUrl(comment.inReplyTo, t)
if (!inReplyToComment) throw new Error('Unknown replied comment ' + comment.inReplyTo)
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 })
if (video.isOwned()) {
// Don't resend the activity to the sender
const exceptions = [ byActor ]
await forwardActivity(activity, t, exceptions)
}
})
}