diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 1ddd817db..102e54b19 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { ActivityCreate, VideoTorrentObject } from '../../../../shared' | 2 | import { ActivityCreate, VideoTorrentObject } from '../../../../shared' |
3 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' | 3 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' |
4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' | ||
4 | import { VideoRateType } from '../../../../shared/models/videos' | 5 | import { VideoRateType } from '../../../../shared/models/videos' |
5 | import { logger, retryTransactionWrapper } from '../../../helpers' | 6 | import { logger, retryTransactionWrapper } from '../../../helpers' |
6 | import { sequelizeTypescript } from '../../../initializers' | 7 | import { sequelizeTypescript } from '../../../initializers' |
@@ -9,6 +10,7 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
9 | import { TagModel } from '../../../models/video/tag' | 10 | import { TagModel } from '../../../models/video/tag' |
10 | import { VideoModel } from '../../../models/video/video' | 11 | import { VideoModel } from '../../../models/video/video' |
11 | import { VideoAbuseModel } from '../../../models/video/video-abuse' | 12 | import { VideoAbuseModel } from '../../../models/video/video-abuse' |
13 | import { VideoCommentModel } from '../../../models/video/video-comment' | ||
12 | import { VideoFileModel } from '../../../models/video/video-file' | 14 | import { VideoFileModel } from '../../../models/video/video-file' |
13 | import { getOrCreateActorAndServerAndModel } from '../actor' | 15 | import { getOrCreateActorAndServerAndModel } from '../actor' |
14 | import { forwardActivity } from '../send/misc' | 16 | import { forwardActivity } from '../send/misc' |
@@ -28,6 +30,8 @@ async function processCreateActivity (activity: ActivityCreate) { | |||
28 | return processCreateVideo(actor, activity) | 30 | return processCreateVideo(actor, activity) |
29 | } else if (activityType === 'Flag') { | 31 | } else if (activityType === 'Flag') { |
30 | return processCreateVideoAbuse(actor, activityObject as VideoAbuseObject) | 32 | return processCreateVideoAbuse(actor, activityObject as VideoAbuseObject) |
33 | } else if (activityType === 'Note') { | ||
34 | return processCreateVideoComment(actor, activity) | ||
31 | } | 35 | } |
32 | 36 | ||
33 | logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) | 37 | logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id }) |
@@ -184,7 +188,7 @@ function createVideoDislike (byActor: ActorModel, activity: ActivityCreate) { | |||
184 | }) | 188 | }) |
185 | } | 189 | } |
186 | 190 | ||
187 | async function processCreateView (byAccount: ActorModel, activity: ActivityCreate) { | 191 | async function processCreateView (byActor: ActorModel, activity: ActivityCreate) { |
188 | const view = activity.object as ViewObject | 192 | const view = activity.object as ViewObject |
189 | 193 | ||
190 | const video = await VideoModel.loadByUrlAndPopulateAccount(view.object) | 194 | const video = await VideoModel.loadByUrlAndPopulateAccount(view.object) |
@@ -198,7 +202,7 @@ async function processCreateView (byAccount: ActorModel, activity: ActivityCreat | |||
198 | 202 | ||
199 | if (video.isOwned()) { | 203 | if (video.isOwned()) { |
200 | // Don't resend the activity to the sender | 204 | // Don't resend the activity to the sender |
201 | const exceptions = [ byAccount ] | 205 | const exceptions = [ byActor ] |
202 | await forwardActivity(activity, undefined, exceptions) | 206 | await forwardActivity(activity, undefined, exceptions) |
203 | } | 207 | } |
204 | } | 208 | } |
@@ -236,3 +240,48 @@ function addRemoteVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAb | |||
236 | logger.info('Remote abuse for video uuid %s created', videoAbuseToCreateData.object) | 240 | logger.info('Remote abuse for video uuid %s created', videoAbuseToCreateData.object) |
237 | }) | 241 | }) |
238 | } | 242 | } |
243 | |||
244 | function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) { | ||
245 | const options = { | ||
246 | arguments: [ byActor, activity ], | ||
247 | errorMessage: 'Cannot create video comment with many retries.' | ||
248 | } | ||
249 | |||
250 | return retryTransactionWrapper(createVideoComment, options) | ||
251 | } | ||
252 | |||
253 | function createVideoComment (byActor: ActorModel, activity: ActivityCreate) { | ||
254 | const comment = activity.object as VideoCommentObject | ||
255 | const byAccount = byActor.Account | ||
256 | |||
257 | if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url) | ||
258 | |||
259 | return sequelizeTypescript.transaction(async t => { | ||
260 | const video = await VideoModel.loadByUrl(comment.inReplyTo, t) | ||
261 | |||
262 | // This is a new thread | ||
263 | if (video) { | ||
264 | return VideoCommentModel.create({ | ||
265 | url: comment.id, | ||
266 | text: comment.content, | ||
267 | originCommentId: null, | ||
268 | inReplyToComment: null, | ||
269 | videoId: video.id, | ||
270 | actorId: byActor.id | ||
271 | }, { transaction: t }) | ||
272 | } | ||
273 | |||
274 | const inReplyToComment = await VideoCommentModel.loadByUrl(comment.inReplyTo, t) | ||
275 | if (!inReplyToComment) throw new Error('Unknown replied comment ' + comment.inReplyTo) | ||
276 | |||
277 | const originCommentId = inReplyToComment.originCommentId || inReplyToComment.id | ||
278 | return VideoCommentModel.create({ | ||
279 | url: comment.id, | ||
280 | text: comment.content, | ||
281 | originCommentId, | ||
282 | inReplyToCommentId: inReplyToComment.id, | ||
283 | videoId: inReplyToComment.videoId, | ||
284 | actorId: byActor.id | ||
285 | }, { transaction: t }) | ||
286 | }) | ||
287 | } | ||