mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Support refusing remote comments
This commit is contained in:
parent
b569b2c607
commit
b2a70e3ca2
6 changed files with 311 additions and 202 deletions
|
@ -109,8 +109,10 @@ async function processCreateVideoComment (activity: ActivityCreate, byActor: MAc
|
|||
let video: MVideoAccountLightBlacklistAllFiles
|
||||
let created: boolean
|
||||
let comment: MCommentOwnerVideo
|
||||
|
||||
try {
|
||||
const resolveThreadResult = await resolveThread({ url: commentObject.id, isVideo: false })
|
||||
if (!resolveThreadResult) return // Comment not accepted
|
||||
|
||||
video = resolveThreadResult.video
|
||||
created = resolveThreadResult.commentCreated
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue