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.ts33
1 files changed, 16 insertions, 17 deletions
diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts
index 722147b69..760da719d 100644
--- a/server/lib/activitypub/video-comments.ts
+++ b/server/lib/activitypub/video-comments.ts
@@ -29,10 +29,11 @@ async function addVideoComments (commentUrls: string[]) {
29 29
30async function resolveThread (params: ResolveThreadParams): ResolveThreadResult { 30async function resolveThread (params: ResolveThreadParams): ResolveThreadResult {
31 const { url, isVideo } = params 31 const { url, isVideo } = params
32
32 if (params.commentCreated === undefined) params.commentCreated = false 33 if (params.commentCreated === undefined) params.commentCreated = false
33 if (params.comments === undefined) params.comments = [] 34 if (params.comments === undefined) params.comments = []
34 35
35 // If it is not a video, or if we don't know if it's a video 36 // If it is not a video, or if we don't know if it's a video, try to get the thread from DB
36 if (isVideo === false || isVideo === undefined) { 37 if (isVideo === false || isVideo === undefined) {
37 const result = await resolveCommentFromDB(params) 38 const result = await resolveCommentFromDB(params)
38 if (result) return result 39 if (result) return result
@@ -42,7 +43,7 @@ async function resolveThread (params: ResolveThreadParams): ResolveThreadResult
42 // If it is a video, or if we don't know if it's a video 43 // If it is a video, or if we don't know if it's a video
43 if (isVideo === true || isVideo === undefined) { 44 if (isVideo === true || isVideo === undefined) {
44 // Keep await so we catch the exception 45 // Keep await so we catch the exception
45 return await tryResolveThreadFromVideo(params) 46 return await tryToResolveThreadFromVideo(params)
46 } 47 }
47 } catch (err) { 48 } catch (err) {
48 logger.debug('Cannot resolve thread from video %s, maybe because it was not a video', url, { err }) 49 logger.debug('Cannot resolve thread from video %s, maybe because it was not a video', url, { err })
@@ -62,28 +63,26 @@ async function resolveCommentFromDB (params: ResolveThreadParams) {
62 const { url, comments, commentCreated } = params 63 const { url, comments, commentCreated } = params
63 64
64 const commentFromDatabase = await VideoCommentModel.loadByUrlAndPopulateReplyAndVideoUrlAndAccount(url) 65 const commentFromDatabase = await VideoCommentModel.loadByUrlAndPopulateReplyAndVideoUrlAndAccount(url)
65 if (commentFromDatabase) { 66 if (!commentFromDatabase) return undefined
66 let parentComments = comments.concat([ commentFromDatabase ])
67 67
68 // Speed up things and resolve directly the thread 68 let parentComments = comments.concat([ commentFromDatabase ])
69 if (commentFromDatabase.InReplyToVideoComment) {
70 const data = await VideoCommentModel.listThreadParentComments(commentFromDatabase, undefined, 'DESC')
71 69
72 parentComments = parentComments.concat(data) 70 // Speed up things and resolve directly the thread
73 } 71 if (commentFromDatabase.InReplyToVideoComment) {
72 const data = await VideoCommentModel.listThreadParentComments(commentFromDatabase, undefined, 'DESC')
74 73
75 return resolveThread({ 74 parentComments = parentComments.concat(data)
76 url: commentFromDatabase.Video.url,
77 comments: parentComments,
78 isVideo: true,
79 commentCreated
80 })
81 } 75 }
82 76
83 return undefined 77 return resolveThread({
78 url: commentFromDatabase.Video.url,
79 comments: parentComments,
80 isVideo: true,
81 commentCreated
82 })
84} 83}
85 84
86async function tryResolveThreadFromVideo (params: ResolveThreadParams) { 85async function tryToResolveThreadFromVideo (params: ResolveThreadParams) {
87 const { url, comments, commentCreated } = params 86 const { url, comments, commentCreated } = params
88 87
89 // Maybe it's a reply to a video? 88 // Maybe it's a reply to a video?