diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-08 10:00:35 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-08 10:15:27 +0100 |
commit | 93ef8a9d02059da2fc90efedb7755c97e9e19ef4 (patch) | |
tree | dfde0d2fdb63277d94491265171add41acf091c3 /server/lib/activitypub/process | |
parent | 57a49263e48739c31cd339730ac4cb24e3d5d723 (diff) | |
download | PeerTube-93ef8a9d02059da2fc90efedb7755c97e9e19ef4.tar.gz PeerTube-93ef8a9d02059da2fc90efedb7755c97e9e19ef4.tar.zst PeerTube-93ef8a9d02059da2fc90efedb7755c97e9e19ef4.zip |
Send comment to followers and parents
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index ffd20fe74..a97f6ae83 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -13,8 +13,9 @@ import { VideoModel } from '../../../models/video/video' | |||
13 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 13 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
14 | import { VideoCommentModel } from '../../../models/video/video-comment' | 14 | import { VideoCommentModel } from '../../../models/video/video-comment' |
15 | import { VideoFileModel } from '../../../models/video/video-file' | 15 | import { VideoFileModel } from '../../../models/video/video-file' |
16 | import { VideoShareModel } from '../../../models/video/video-share' | ||
16 | import { getOrCreateActorAndServerAndModel } from '../actor' | 17 | import { getOrCreateActorAndServerAndModel } from '../actor' |
17 | import { forwardActivity } from '../send/misc' | 18 | import { forwardActivity, getActorsInvolvedInVideo } from '../send/misc' |
18 | import { generateThumbnailFromUrl } from '../videos' | 19 | import { generateThumbnailFromUrl } from '../videos' |
19 | import { addVideoComments, addVideoShares, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' | 20 | import { addVideoComments, addVideoShares, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' |
20 | 21 | ||
@@ -266,18 +267,19 @@ function createVideoComment (byActor: ActorModel, activity: ActivityCreate) { | |||
266 | if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) | 267 | if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) |
267 | 268 | ||
268 | return sequelizeTypescript.transaction(async t => { | 269 | return sequelizeTypescript.transaction(async t => { |
269 | let video = await VideoModel.loadByUrl(comment.inReplyTo, t) | 270 | let video = await VideoModel.loadByUrlAndPopulateAccount(comment.inReplyTo, t) |
271 | let objectToCreate | ||
270 | 272 | ||
271 | // This is a new thread | 273 | // This is a new thread |
272 | if (video) { | 274 | if (video) { |
273 | await VideoCommentModel.create({ | 275 | objectToCreate = { |
274 | url: comment.id, | 276 | url: comment.id, |
275 | text: comment.content, | 277 | text: comment.content, |
276 | originCommentId: null, | 278 | originCommentId: null, |
277 | inReplyToComment: null, | 279 | inReplyToComment: null, |
278 | videoId: video.id, | 280 | videoId: video.id, |
279 | accountId: byAccount.id | 281 | accountId: byAccount.id |
280 | }, { transaction: t }) | 282 | } |
281 | } else { | 283 | } else { |
282 | const inReplyToComment = await VideoCommentModel.loadByUrl(comment.inReplyTo, t) | 284 | const inReplyToComment = await VideoCommentModel.loadByUrl(comment.inReplyTo, t) |
283 | if (!inReplyToComment) throw new Error('Unknown replied comment ' + comment.inReplyTo) | 285 | if (!inReplyToComment) throw new Error('Unknown replied comment ' + comment.inReplyTo) |
@@ -285,20 +287,34 @@ function createVideoComment (byActor: ActorModel, activity: ActivityCreate) { | |||
285 | video = await VideoModel.load(inReplyToComment.videoId) | 287 | video = await VideoModel.load(inReplyToComment.videoId) |
286 | 288 | ||
287 | const originCommentId = inReplyToComment.originCommentId || inReplyToComment.id | 289 | const originCommentId = inReplyToComment.originCommentId || inReplyToComment.id |
288 | await VideoCommentModel.create({ | 290 | objectToCreate = { |
289 | url: comment.id, | 291 | url: comment.id, |
290 | text: comment.content, | 292 | text: comment.content, |
291 | originCommentId, | 293 | originCommentId, |
292 | inReplyToCommentId: inReplyToComment.id, | 294 | inReplyToCommentId: inReplyToComment.id, |
293 | videoId: video.id, | 295 | videoId: video.id, |
294 | accountId: byAccount.id | 296 | accountId: byAccount.id |
295 | }, { transaction: t }) | 297 | } |
296 | } | 298 | } |
297 | 299 | ||
298 | if (video.isOwned()) { | 300 | const options = { |
301 | where: { | ||
302 | url: objectToCreate.url | ||
303 | }, | ||
304 | defaults: objectToCreate, | ||
305 | transaction: t | ||
306 | } | ||
307 | const [ ,created ] = await VideoCommentModel.findOrCreate(options) | ||
308 | |||
309 | if (video.isOwned() && created === true) { | ||
299 | // Don't resend the activity to the sender | 310 | // Don't resend the activity to the sender |
300 | const exceptions = [ byActor ] | 311 | const exceptions = [ byActor ] |
301 | await forwardActivity(activity, t, exceptions) | 312 | |
313 | // Mastodon does not add our announces in audience, so we forward to them manually | ||
314 | const additionalActors = await getActorsInvolvedInVideo(video, t) | ||
315 | const additionalFollowerUrls = additionalActors.map(a => a.followersUrl) | ||
316 | |||
317 | await forwardActivity(activity, t, exceptions, additionalFollowerUrls) | ||
302 | } | 318 | } |
303 | }) | 319 | }) |
304 | } | 320 | } |