diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-27 10:39:31 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-27 10:39:31 +0100 |
commit | ea44f375f5d3da06ca0aebfe871b9f924a26ec29 (patch) | |
tree | ad2e3a458fdbeb11fae8b2215e0619df1aa6e20c /server/lib/activitypub/process/process-create.ts | |
parent | e2e22e40f91018cfaf244e0df9a4a93e4f6d0502 (diff) | |
download | PeerTube-ea44f375f5d3da06ca0aebfe871b9f924a26ec29.tar.gz PeerTube-ea44f375f5d3da06ca0aebfe871b9f924a26ec29.tar.zst PeerTube-ea44f375f5d3da06ca0aebfe871b9f924a26ec29.zip |
Send video comment comments to followers/origin
Diffstat (limited to 'server/lib/activitypub/process/process-create.ts')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 36 |
1 files changed, 22 insertions, 14 deletions
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) { | |||
257 | if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) | 257 | if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) |
258 | 258 | ||
259 | return sequelizeTypescript.transaction(async t => { | 259 | return sequelizeTypescript.transaction(async t => { |
260 | const video = await VideoModel.loadByUrl(comment.inReplyTo, t) | 260 | let video = await VideoModel.loadByUrl(comment.inReplyTo, t) |
261 | 261 | ||
262 | // This is a new thread | 262 | // This is a new thread |
263 | if (video) { | 263 | if (video) { |
264 | return VideoCommentModel.create({ | 264 | await VideoCommentModel.create({ |
265 | url: comment.id, | 265 | url: comment.id, |
266 | text: comment.content, | 266 | text: comment.content, |
267 | originCommentId: null, | 267 | originCommentId: null, |
@@ -269,19 +269,27 @@ function createVideoComment (byActor: ActorModel, activity: ActivityCreate) { | |||
269 | videoId: video.id, | 269 | videoId: video.id, |
270 | accountId: byAccount.id | 270 | accountId: byAccount.id |
271 | }, { transaction: t }) | 271 | }, { transaction: t }) |
272 | } | 272 | } else { |
273 | const inReplyToComment = await VideoCommentModel.loadByUrl(comment.inReplyTo, t) | ||
274 | if (!inReplyToComment) throw new Error('Unknown replied comment ' + comment.inReplyTo) | ||
273 | 275 | ||
274 | const inReplyToComment = await VideoCommentModel.loadByUrl(comment.inReplyTo, t) | 276 | video = await VideoModel.load(inReplyToComment.videoId) |
275 | if (!inReplyToComment) throw new Error('Unknown replied comment ' + comment.inReplyTo) | ||
276 | 277 | ||
277 | const originCommentId = inReplyToComment.originCommentId || inReplyToComment.id | 278 | const originCommentId = inReplyToComment.originCommentId || inReplyToComment.id |
278 | return VideoCommentModel.create({ | 279 | await VideoCommentModel.create({ |
279 | url: comment.id, | 280 | url: comment.id, |
280 | text: comment.content, | 281 | text: comment.content, |
281 | originCommentId, | 282 | originCommentId, |
282 | inReplyToCommentId: inReplyToComment.id, | 283 | inReplyToCommentId: inReplyToComment.id, |
283 | videoId: inReplyToComment.videoId, | 284 | videoId: video.id, |
284 | accountId: byAccount.id | 285 | accountId: byAccount.id |
285 | }, { transaction: t }) | 286 | }, { transaction: t }) |
287 | } | ||
288 | |||
289 | if (video.isOwned()) { | ||
290 | // Don't resend the activity to the sender | ||
291 | const exceptions = [ byActor ] | ||
292 | await forwardActivity(activity, t, exceptions) | ||
293 | } | ||
286 | }) | 294 | }) |
287 | } | 295 | } |