aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/process/process-create.ts53
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 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { ActivityCreate, VideoTorrentObject } from '../../../../shared' 2import { ActivityCreate, VideoTorrentObject } from '../../../../shared'
3import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' 3import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects'
4import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object'
4import { VideoRateType } from '../../../../shared/models/videos' 5import { VideoRateType } from '../../../../shared/models/videos'
5import { logger, retryTransactionWrapper } from '../../../helpers' 6import { logger, retryTransactionWrapper } from '../../../helpers'
6import { sequelizeTypescript } from '../../../initializers' 7import { sequelizeTypescript } from '../../../initializers'
@@ -9,6 +10,7 @@ import { ActorModel } from '../../../models/activitypub/actor'
9import { TagModel } from '../../../models/video/tag' 10import { TagModel } from '../../../models/video/tag'
10import { VideoModel } from '../../../models/video/video' 11import { VideoModel } from '../../../models/video/video'
11import { VideoAbuseModel } from '../../../models/video/video-abuse' 12import { VideoAbuseModel } from '../../../models/video/video-abuse'
13import { VideoCommentModel } from '../../../models/video/video-comment'
12import { VideoFileModel } from '../../../models/video/video-file' 14import { VideoFileModel } from '../../../models/video/video-file'
13import { getOrCreateActorAndServerAndModel } from '../actor' 15import { getOrCreateActorAndServerAndModel } from '../actor'
14import { forwardActivity } from '../send/misc' 16import { 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
187async function processCreateView (byAccount: ActorModel, activity: ActivityCreate) { 191async 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
244function 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
253function 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}