X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Flib%2Factivitypub%2Fvideo-comments.ts;h=b65baf0e95dc49469d7e17c6a10261df7b320fac;hb=e901579b00fbcd8fc0f7b45fd841636329148a34;hp=911c7cd3020b5f334215bd4950095273d9d0d547;hpb=7e98a7df7d04e19ba67163a86c7b876d78d76839;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts index 911c7cd30..b65baf0e9 100644 --- a/server/lib/activitypub/video-comments.ts +++ b/server/lib/activitypub/video-comments.ts @@ -4,7 +4,9 @@ import { logger } from '../../helpers/logger' import { doJSONRequest } from '../../helpers/requests' import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' import { VideoCommentModel } from '../../models/video/video-comment' -import { MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../types/models/video' +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' @@ -103,6 +105,10 @@ async function tryToResolveThreadFromVideo (params: ResolveThreadParams) { firstReply.changed('updatedAt', true) firstReply.Video = video + if (await isRemoteCommentAccepted(firstReply) !== true) { + return undefined + } + comments[comments.length - 1] = await firstReply.save() for (let i = comments.length - 2; i >= 0; i--) { @@ -113,6 +119,10 @@ async function tryToResolveThreadFromVideo (params: ResolveThreadParams) { comment.changed('updatedAt', true) comment.Video = video + if (await isRemoteCommentAccepted(comment) !== true) { + return undefined + } + comments[i] = await comment.save() } @@ -169,3 +179,26 @@ async function resolveRemoteParentComment (params: ResolveThreadParams) { commentCreated: true }) } + +async function isRemoteCommentAccepted (comment: MComment) { + // Already created + if (comment.id) return true + + const acceptParameters = { + comment + } + + const acceptedResult = await Hooks.wrapFun( + isRemoteVideoCommentAccepted, + acceptParameters, + 'filter:activity-pub.remote-video-comment.create.accept.result' + ) + + if (!acceptedResult || acceptedResult.accepted !== true) { + logger.info('Refused to create a remote comment.', { acceptedResult, acceptParameters }) + + return false + } + + return true +}