-import { getOrCreateActorAndServerAndModel } from './actor'
-import { getOrCreateVideoAndAccountAndChannel } from './videos'
-import * as Bluebird from 'bluebird'
-import { checkUrlsSameHost } from '../../helpers/activitypub'
-
-async function videoCommentActivityObjectToDBAttributes (video: VideoModel, actor: ActorModel, comment: VideoCommentObject) {
- let originCommentId: number = null
- let inReplyToCommentId: number = null
-
- // If this is not a reply to the video (thread), create or get the parent comment
- if (video.url !== comment.inReplyTo) {
- const { comment: parent } = await addVideoComment(video, comment.inReplyTo)
- if (!parent) {
- logger.warn('Cannot fetch or get parent comment %s of comment %s.', comment.inReplyTo, comment.id)
- return undefined
+import { MComment, MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../types/models/video'
+import { isRemoteVideoCommentAccepted } from '../moderation'
+import { Hooks } from '../plugins/hooks'
+import { getOrCreateAPActor } from './actors'
+import { checkUrlsSameHost } from './url'
+import { getOrCreateAPVideo } from './videos'
+
+type ResolveThreadParams = {
+ url: string
+ comments?: MCommentOwner[]
+ isVideo?: boolean
+ commentCreated?: boolean
+}
+type ResolveThreadResult = Promise<{ video: MVideoAccountLightBlacklistAllFiles, comment: MCommentOwnerVideo, commentCreated: boolean }>
+
+async function addVideoComments (commentUrls: string[]) {
+ return map(commentUrls, async commentUrl => {
+ try {
+ await resolveThread({ url: commentUrl, isVideo: false })
+ } catch (err) {
+ logger.warn('Cannot resolve thread %s.', commentUrl, { err })