aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/video-comments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/video-comments.ts')
-rw-r--r--server/lib/activitypub/video-comments.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts
index beff557bc..ffbd3a64e 100644
--- a/server/lib/activitypub/video-comments.ts
+++ b/server/lib/activitypub/video-comments.ts
@@ -16,7 +16,7 @@ async function videoCommentActivityObjectToDBAttributes (video: VideoModel, acto
16 16
17 // If this is not a reply to the video (thread), create or get the parent comment 17 // If this is not a reply to the video (thread), create or get the parent comment
18 if (video.url !== comment.inReplyTo) { 18 if (video.url !== comment.inReplyTo) {
19 const [ parent ] = await addVideoComment(video, comment.inReplyTo) 19 const { comment: parent } = await addVideoComment(video, comment.inReplyTo)
20 if (!parent) { 20 if (!parent) {
21 logger.warn('Cannot fetch or get parent comment %s of comment %s.', comment.inReplyTo, comment.id) 21 logger.warn('Cannot fetch or get parent comment %s of comment %s.', comment.inReplyTo, comment.id)
22 return undefined 22 return undefined
@@ -55,22 +55,24 @@ async function addVideoComment (videoInstance: VideoModel, commentUrl: string) {
55 55
56 if (sanitizeAndCheckVideoCommentObject(body) === false) { 56 if (sanitizeAndCheckVideoCommentObject(body) === false) {
57 logger.debug('Remote video comment JSON is not valid.', { body }) 57 logger.debug('Remote video comment JSON is not valid.', { body })
58 return undefined 58 return { created: false }
59 } 59 }
60 60
61 const actorUrl = body.attributedTo 61 const actorUrl = body.attributedTo
62 if (!actorUrl) return [] 62 if (!actorUrl) return { created: false }
63 63
64 const actor = await getOrCreateActorAndServerAndModel(actorUrl) 64 const actor = await getOrCreateActorAndServerAndModel(actorUrl)
65 const entry = await videoCommentActivityObjectToDBAttributes(videoInstance, actor, body) 65 const entry = await videoCommentActivityObjectToDBAttributes(videoInstance, actor, body)
66 if (!entry) return [] 66 if (!entry) return { created: false }
67 67
68 return VideoCommentModel.findOrCreate({ 68 const [ comment, created ] = await VideoCommentModel.findOrCreate({
69 where: { 69 where: {
70 url: body.id 70 url: body.id
71 }, 71 },
72 defaults: entry 72 defaults: entry
73 }) 73 })
74
75 return { comment, created }
74} 76}
75 77
76async function resolveThread (url: string, comments: VideoCommentModel[] = []) { 78async function resolveThread (url: string, comments: VideoCommentModel[] = []) {
@@ -91,6 +93,7 @@ async function resolveThread (url: string, comments: VideoCommentModel[] = []) {
91 93
92 try { 94 try {
93 // Maybe it's a reply to a video? 95 // Maybe it's a reply to a video?
96 // If yes, it's done: we resolved all the thread
94 const { video } = await getOrCreateVideoAndAccountAndChannel(url) 97 const { video } = await getOrCreateVideoAndAccountAndChannel(url)
95 98
96 if (comments.length !== 0) { 99 if (comments.length !== 0) {