async function resolveThread (params: ResolveThreadParams): ResolveThreadResult {
const { url, isVideo } = params
+
if (params.commentCreated === undefined) params.commentCreated = false
if (params.comments === undefined) params.comments = []
- // If it is not a video, or if we don't know if it's a video
+ // If it is not a video, or if we don't know if it's a video, try to get the thread from DB
if (isVideo === false || isVideo === undefined) {
const result = await resolveCommentFromDB(params)
if (result) return result
// If it is a video, or if we don't know if it's a video
if (isVideo === true || isVideo === undefined) {
// Keep await so we catch the exception
- return await tryResolveThreadFromVideo(params)
+ return await tryToResolveThreadFromVideo(params)
}
} catch (err) {
logger.debug('Cannot resolve thread from video %s, maybe because it was not a video', url, { err })
const { url, comments, commentCreated } = params
const commentFromDatabase = await VideoCommentModel.loadByUrlAndPopulateReplyAndVideoUrlAndAccount(url)
- if (commentFromDatabase) {
- let parentComments = comments.concat([ commentFromDatabase ])
+ if (!commentFromDatabase) return undefined
- // Speed up things and resolve directly the thread
- if (commentFromDatabase.InReplyToVideoComment) {
- const data = await VideoCommentModel.listThreadParentComments(commentFromDatabase, undefined, 'DESC')
+ let parentComments = comments.concat([ commentFromDatabase ])
- parentComments = parentComments.concat(data)
- }
+ // Speed up things and resolve directly the thread
+ if (commentFromDatabase.InReplyToVideoComment) {
+ const data = await VideoCommentModel.listThreadParentComments(commentFromDatabase, undefined, 'DESC')
- return resolveThread({
- url: commentFromDatabase.Video.url,
- comments: parentComments,
- isVideo: true,
- commentCreated
- })
+ parentComments = parentComments.concat(data)
}
- return undefined
+ return resolveThread({
+ url: commentFromDatabase.Video.url,
+ comments: parentComments,
+ isVideo: true,
+ commentCreated
+ })
}
-async function tryResolveThreadFromVideo (params: ResolveThreadParams) {
+async function tryToResolveThreadFromVideo (params: ResolveThreadParams) {
const { url, comments, commentCreated } = params
// Maybe it's a reply to a video?