+ if (video.isOwned() && !video.hasPrivacyForFederation()) {
+ throw new Error('Cannot resolve thread of video with privacy that is not compatible with federation')
+ }
+
+ 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()