X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fvideo-comments.ts;h=c3fc6b4621926179d24621a38e8138ab1811051b;hb=b91bc1d1f3591c35ab4426f6ab594b4bd9f1ef62;hp=5868e7297e5fd1b31b2aec448fa24209b79545f8;hpb=5c6d985faeef1d6793d3f44ca6374f1a9b722806;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts index 5868e7297..c3fc6b462 100644 --- a/server/lib/activitypub/video-comments.ts +++ b/server/lib/activitypub/video-comments.ts @@ -2,7 +2,7 @@ import { VideoCommentObject } from '../../../shared/models/activitypub/objects/v import { sanitizeAndCheckVideoCommentObject } from '../../helpers/custom-validators/activitypub/video-comments' import { logger } from '../../helpers/logger' import { doRequest } from '../../helpers/requests' -import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers' +import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' import { ActorModel } from '../../models/activitypub/actor' import { VideoModel } from '../../models/video/video' import { VideoCommentModel } from '../../models/video/video-comment' @@ -34,8 +34,7 @@ async function videoCommentActivityObjectToDBAttributes (video: VideoModel, acto accountId: actor.Account.id, inReplyToCommentId, originCommentId, - createdAt: new Date(comment.published), - updatedAt: new Date(comment.updated) + createdAt: new Date(comment.published) } } @@ -70,21 +69,19 @@ async function addVideoComment (videoInstance: VideoModel, commentUrl: string) { throw new Error(`Comment url ${commentUrl} host is different from the AP object id ${body.id}`) } - const actor = await getOrCreateActorAndServerAndModel(actorUrl) + const actor = await getOrCreateActorAndServerAndModel(actorUrl, 'all') const entry = await videoCommentActivityObjectToDBAttributes(videoInstance, actor, body) if (!entry) return { created: false } - const [ comment, created ] = await VideoCommentModel.findOrCreate({ - where: { - url: body.id - }, - defaults: entry - }) + const [ comment, created ] = await VideoCommentModel.upsert(entry, { returning: true }) + comment.Account = actor.Account + comment.Video = videoInstance return { comment, created } } -async function resolveThread (url: string, comments: VideoCommentModel[] = []) { +type ResolveThreadResult = Promise<{ video: VideoModel, parents: VideoCommentModel[] }> +async function resolveThread (url: string, comments: VideoCommentModel[] = []): ResolveThreadResult { // Already have this comment? const commentFromDatabase = await VideoCommentModel.loadByUrlAndPopulateReplyAndVideo(url) if (commentFromDatabase) { @@ -165,7 +162,6 @@ async function resolveThread (url: string, comments: VideoCommentModel[] = []) { return resolveThread(body.inReplyTo, comments.concat([ comment ])) } - } export {