- try {
- // Maybe it's a reply to a video?
- const { video } = await getOrCreateAccountAndVideoAndChannel(url)
-
- if (comments.length !== 0) {
- const firstReply = comments[ comments.length - 1 ]
- firstReply.inReplyToCommentId = null
- firstReply.originCommentId = null
- firstReply.videoId = video.id
- comments[comments.length - 1] = await firstReply.save()
-
- for (let i = comments.length - 2; i >= 0; i--) {
- const comment = comments[ i ]
- comment.originCommentId = firstReply.id
- comment.inReplyToCommentId = comments[ i + 1 ].id
- comment.videoId = video.id
-
- comments[i] = await comment.save()
- }
+ return undefined
+}
+
+async function tryResolveThreadFromVideo (params: ResolveThreadParams) {
+ const { url, comments, commentCreated } = params
+
+ // Maybe it's a reply to a video?
+ // If yes, it's done: we resolved all the thread
+ const syncParam = { likes: true, dislikes: true, shares: true, comments: false, thumbnail: true, refreshVideo: false }
+ const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: url, syncParam })
+
+ let resultComment: MCommentOwnerVideo
+ if (comments.length !== 0) {
+ const firstReply = comments[ comments.length - 1 ] as MCommentOwnerVideo
+ firstReply.inReplyToCommentId = null
+ firstReply.originCommentId = null
+ firstReply.videoId = video.id
+ firstReply.changed('updatedAt', true)
+ firstReply.Video = video
+
+ comments[comments.length - 1] = await firstReply.save()
+
+ for (let i = comments.length - 2; i >= 0; i--) {
+ const comment = comments[ i ] as MCommentOwnerVideo
+ comment.originCommentId = firstReply.id
+ comment.inReplyToCommentId = comments[ i + 1 ].id
+ comment.videoId = video.id
+ comment.changed('updatedAt', true)
+ comment.Video = video
+
+ comments[i] = await comment.save()