]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Support refusing remote comments
authorChocobozzz <me@florianbigard.com>
Fri, 23 Sep 2022 09:38:18 +0000 (11:38 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 23 Sep 2022 09:38:18 +0000 (11:38 +0200)
server/lib/activitypub/process/process-create.ts
server/lib/activitypub/video-comments.ts
server/lib/moderation.ts
server/tests/fixtures/peertube-plugin-test/main.js
server/tests/plugins/filter-hooks.ts
shared/models/plugins/server/server-hook.model.ts

index 76ed37aae3cf266871c18ddac13c8eab6135e1da..1e6e8956ccc8e349b91946ce95efdbdf8c3fd24a 100644 (file)
@@ -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
index 911c7cd3020b5f334215bd4950095273d9d0d547..b65baf0e95dc49469d7e17c6a10261df7b320fac 100644 (file)
@@ -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
+}
index c23f5b6a6cd51780cd98d8127b3ac64348bec958..43c58c980d9d1f4269fcefb7ea80dcc86afd4f75 100644 (file)
@@ -13,18 +13,15 @@ import {
   MAbuseFull,
   MAccountDefault,
   MAccountLight,
+  MComment,
   MCommentAbuseAccountVideo,
   MCommentOwnerVideo,
   MUser,
   MVideoAbuseVideoFull,
   MVideoAccountLightBlacklistAllFiles
 } from '@server/types/models'
-import { ActivityCreate } from '../../shared/models/activitypub'
-import { VideoObject } from '../../shared/models/activitypub/objects'
-import { VideoCommentObject } from '../../shared/models/activitypub/objects/video-comment-object'
 import { LiveVideoCreate, VideoCreate, VideoImportCreate } from '../../shared/models/videos'
 import { VideoCommentCreate } from '../../shared/models/videos/comment'
-import { ActorModel } from '../models/actor/actor'
 import { UserModel } from '../models/user/user'
 import { VideoModel } from '../models/video/video'
 import { VideoCommentModel } from '../models/video/video-comment'
@@ -36,7 +33,9 @@ export type AcceptResult = {
   errorMessage?: string
 }
 
-// Can be filtered by plugins
+// ---------------------------------------------------------------------------
+
+// Stub function that can be filtered by plugins
 function isLocalVideoAccepted (object: {
   videoBody: VideoCreate
   videoFile: VideoUploadFile
@@ -45,6 +44,9 @@ function isLocalVideoAccepted (object: {
   return { accepted: true }
 }
 
+// ---------------------------------------------------------------------------
+
+// Stub function that can be filtered by plugins
 function isLocalLiveVideoAccepted (object: {
   liveVideoBody: LiveVideoCreate
   user: UserModel
@@ -52,6 +54,9 @@ function isLocalLiveVideoAccepted (object: {
   return { accepted: true }
 }
 
+// ---------------------------------------------------------------------------
+
+// Stub function that can be filtered by plugins
 function isLocalVideoThreadAccepted (_object: {
   commentBody: VideoCommentCreate
   video: VideoModel
@@ -60,6 +65,7 @@ function isLocalVideoThreadAccepted (_object: {
   return { accepted: true }
 }
 
+// Stub function that can be filtered by plugins
 function isLocalVideoCommentReplyAccepted (_object: {
   commentBody: VideoCommentCreate
   parentComment: VideoCommentModel
@@ -69,22 +75,18 @@ function isLocalVideoCommentReplyAccepted (_object: {
   return { accepted: true }
 }
 
-function isRemoteVideoAccepted (_object: {
-  activity: ActivityCreate
-  videoAP: VideoObject
-  byActor: ActorModel
-}): AcceptResult {
-  return { accepted: true }
-}
+// ---------------------------------------------------------------------------
 
+// Stub function that can be filtered by plugins
 function isRemoteVideoCommentAccepted (_object: {
-  activity: ActivityCreate
-  commentAP: VideoCommentObject
-  byActor: ActorModel
+  comment: MComment
 }): AcceptResult {
   return { accepted: true }
 }
 
+// ---------------------------------------------------------------------------
+
+// Stub function that can be filtered by plugins
 function isPreImportVideoAccepted (object: {
   videoImportBody: VideoImportCreate
   user: MUser
@@ -92,6 +94,7 @@ function isPreImportVideoAccepted (object: {
   return { accepted: true }
 }
 
+// Stub function that can be filtered by plugins
 function isPostImportVideoAccepted (object: {
   videoFilePath: PathLike
   videoFile: VideoFileModel
@@ -100,6 +103,8 @@ function isPostImportVideoAccepted (object: {
   return { accepted: true }
 }
 
+// ---------------------------------------------------------------------------
+
 async function createVideoAbuse (options: {
   baseAbuse: FilteredModelAttributes<AbuseModel>
   videoInstance: MVideoAccountLightBlacklistAllFiles
@@ -189,12 +194,13 @@ function createAccountAbuse (options: {
   })
 }
 
+// ---------------------------------------------------------------------------
+
 export {
   isLocalLiveVideoAccepted,
 
   isLocalVideoAccepted,
   isLocalVideoThreadAccepted,
-  isRemoteVideoAccepted,
   isRemoteVideoCommentAccepted,
   isLocalVideoCommentReplyAccepted,
   isPreImportVideoAccepted,
index 813482a270f0e90198083befb8630f99f89539c7..19dccf26e8bff975ff23360b281071ab96749db3 100644 (file)
@@ -178,6 +178,8 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
     }
   })
 
+  // ---------------------------------------------------------------------------
+
   registerHook({
     target: 'filter:api.video-thread.create.accept.result',
     handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody)
@@ -188,6 +190,13 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
     handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody)
   })
 
+  registerHook({
+    target: 'filter:activity-pub.remote-video-comment.create.accept.result',
+    handler: ({ accepted }, { comment }) => checkCommentBadWord(accepted, comment)
+  })
+
+  // ---------------------------------------------------------------------------
+
   registerHook({
     target: 'filter:api.video-threads.list.params',
     handler: obj => addToCount(obj)
index 026c7e8566d1dab86d5147f9d6f0018d39ee7e87..ae4b3cf5fa2dc2faee35561174138488c70f7098 100644 (file)
@@ -64,232 +64,289 @@ describe('Test plugin filter hooks', function () {
     })
   })
 
-  it('Should run filter:api.videos.list.params', async function () {
-    const { data } = await servers[0].videos.list({ start: 0, count: 2 })
+  describe('Videos', function () {
 
-    // 2 plugins do +1 to the count parameter
-    expect(data).to.have.lengthOf(4)
-  })
+    it('Should run filter:api.videos.list.params', async function () {
+      const { data } = await servers[0].videos.list({ start: 0, count: 2 })
 
-  it('Should run filter:api.videos.list.result', async function () {
-    const { total } = await servers[0].videos.list({ start: 0, count: 0 })
+      // 2 plugins do +1 to the count parameter
+      expect(data).to.have.lengthOf(4)
+    })
 
-    // Plugin do +1 to the total result
-    expect(total).to.equal(11)
-  })
+    it('Should run filter:api.videos.list.result', async function () {
+      const { total } = await servers[0].videos.list({ start: 0, count: 0 })
 
-  it('Should run filter:api.video-playlist.videos.list.params', async function () {
-    const { data } = await servers[0].playlists.listVideos({
-      count: 2,
-      playlistId: videoPlaylistUUID
+      // Plugin do +1 to the total result
+      expect(total).to.equal(11)
     })
 
-    // 1 plugin do +1 to the count parameter
-    expect(data).to.have.lengthOf(3)
-  })
+    it('Should run filter:api.video-playlist.videos.list.params', async function () {
+      const { data } = await servers[0].playlists.listVideos({
+        count: 2,
+        playlistId: videoPlaylistUUID
+      })
 
-  it('Should run filter:api.video-playlist.videos.list.result', async function () {
-    const { total } = await servers[0].playlists.listVideos({
-      count: 0,
-      playlistId: videoPlaylistUUID
+      // 1 plugin do +1 to the count parameter
+      expect(data).to.have.lengthOf(3)
     })
 
-    // Plugin do +1 to the total result
-    expect(total).to.equal(11)
-  })
+    it('Should run filter:api.video-playlist.videos.list.result', async function () {
+      const { total } = await servers[0].playlists.listVideos({
+        count: 0,
+        playlistId: videoPlaylistUUID
+      })
 
-  it('Should run filter:api.accounts.videos.list.params', async function () {
-    const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
+      // Plugin do +1 to the total result
+      expect(total).to.equal(11)
+    })
 
-    // 1 plugin do +1 to the count parameter
-    expect(data).to.have.lengthOf(3)
-  })
+    it('Should run filter:api.accounts.videos.list.params', async function () {
+      const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
 
-  it('Should run filter:api.accounts.videos.list.result', async function () {
-    const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
+      // 1 plugin do +1 to the count parameter
+      expect(data).to.have.lengthOf(3)
+    })
 
-    // Plugin do +2 to the total result
-    expect(total).to.equal(12)
-  })
+    it('Should run filter:api.accounts.videos.list.result', async function () {
+      const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
 
-  it('Should run filter:api.video-channels.videos.list.params', async function () {
-    const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
+      // Plugin do +2 to the total result
+      expect(total).to.equal(12)
+    })
 
-    // 1 plugin do +3 to the count parameter
-    expect(data).to.have.lengthOf(5)
-  })
+    it('Should run filter:api.video-channels.videos.list.params', async function () {
+      const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
 
-  it('Should run filter:api.video-channels.videos.list.result', async function () {
-    const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
+      // 1 plugin do +3 to the count parameter
+      expect(data).to.have.lengthOf(5)
+    })
 
-    // Plugin do +3 to the total result
-    expect(total).to.equal(13)
-  })
+    it('Should run filter:api.video-channels.videos.list.result', async function () {
+      const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
 
-  it('Should run filter:api.user.me.videos.list.params', async function () {
-    const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
+      // Plugin do +3 to the total result
+      expect(total).to.equal(13)
+    })
 
-    // 1 plugin do +4 to the count parameter
-    expect(data).to.have.lengthOf(6)
-  })
+    it('Should run filter:api.user.me.videos.list.params', async function () {
+      const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
 
-  it('Should run filter:api.user.me.videos.list.result', async function () {
-    const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
+      // 1 plugin do +4 to the count parameter
+      expect(data).to.have.lengthOf(6)
+    })
 
-    // Plugin do +4 to the total result
-    expect(total).to.equal(14)
-  })
+    it('Should run filter:api.user.me.videos.list.result', async function () {
+      const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
 
-  it('Should run filter:api.video.get.result', async function () {
-    const video = await servers[0].videos.get({ id: videoUUID })
-    expect(video.name).to.contain('<3')
-  })
+      // Plugin do +4 to the total result
+      expect(total).to.equal(14)
+    })
 
-  it('Should run filter:api.video.upload.accept.result', async function () {
-    await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+    it('Should run filter:api.video.get.result', async function () {
+      const video = await servers[0].videos.get({ id: videoUUID })
+      expect(video.name).to.contain('<3')
+    })
   })
 
-  it('Should run filter:api.live-video.create.accept.result', async function () {
-    const attributes = {
-      name: 'video with bad word',
-      privacy: VideoPrivacy.PUBLIC,
-      channelId: servers[0].store.channel.id
-    }
+  describe('Video/live/import accept', function () {
 
-    await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
-  })
-
-  it('Should run filter:api.video.pre-import-url.accept.result', async function () {
-    const attributes = {
-      name: 'normal title',
-      privacy: VideoPrivacy.PUBLIC,
-      channelId: servers[0].store.channel.id,
-      targetUrl: FIXTURE_URLS.goodVideo + 'bad'
-    }
-    await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
-  })
+    it('Should run filter:api.video.upload.accept.result', async function () {
+      await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+    })
 
-  it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
-    const attributes = {
-      name: 'bad torrent',
-      privacy: VideoPrivacy.PUBLIC,
-      channelId: servers[0].store.channel.id,
-      torrentfile: 'video-720p.torrent' as any
-    }
-    await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
-  })
+    it('Should run filter:api.live-video.create.accept.result', async function () {
+      const attributes = {
+        name: 'video with bad word',
+        privacy: VideoPrivacy.PUBLIC,
+        channelId: servers[0].store.channel.id
+      }
 
-  it('Should run filter:api.video.post-import-url.accept.result', async function () {
-    this.timeout(60000)
+      await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+    })
 
-    let videoImportId: number
+    it('Should run filter:api.video.pre-import-url.accept.result', async function () {
+      const attributes = {
+        name: 'normal title',
+        privacy: VideoPrivacy.PUBLIC,
+        channelId: servers[0].store.channel.id,
+        targetUrl: FIXTURE_URLS.goodVideo + 'bad'
+      }
+      await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+    })
 
-    {
+    it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
       const attributes = {
-        name: 'title with bad word',
+        name: 'bad torrent',
         privacy: VideoPrivacy.PUBLIC,
         channelId: servers[0].store.channel.id,
-        targetUrl: FIXTURE_URLS.goodVideo
+        torrentfile: 'video-720p.torrent' as any
       }
-      const body = await servers[0].imports.importVideo({ attributes })
-      videoImportId = body.id
-    }
+      await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
+    })
 
-    await waitJobs(servers)
+    it('Should run filter:api.video.post-import-url.accept.result', async function () {
+      this.timeout(60000)
 
-    {
-      const body = await servers[0].imports.getMyVideoImports()
-      const videoImports = body.data
+      let videoImportId: number
 
-      const videoImport = videoImports.find(i => i.id === videoImportId)
+      {
+        const attributes = {
+          name: 'title with bad word',
+          privacy: VideoPrivacy.PUBLIC,
+          channelId: servers[0].store.channel.id,
+          targetUrl: FIXTURE_URLS.goodVideo
+        }
+        const body = await servers[0].imports.importVideo({ attributes })
+        videoImportId = body.id
+      }
 
-      expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
-      expect(videoImport.state.label).to.equal('Rejected')
-    }
-  })
+      await waitJobs(servers)
 
-  it('Should run filter:api.video.post-import-torrent.accept.result', async function () {
-    this.timeout(60000)
+      {
+        const body = await servers[0].imports.getMyVideoImports()
+        const videoImports = body.data
 
-    let videoImportId: number
+        const videoImport = videoImports.find(i => i.id === videoImportId)
 
-    {
-      const attributes = {
-        name: 'title with bad word',
-        privacy: VideoPrivacy.PUBLIC,
-        channelId: servers[0].store.channel.id,
-        torrentfile: 'video-720p.torrent' as any
+        expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
+        expect(videoImport.state.label).to.equal('Rejected')
       }
-      const body = await servers[0].imports.importVideo({ attributes })
-      videoImportId = body.id
-    }
+    })
 
-    await waitJobs(servers)
+    it('Should run filter:api.video.post-import-torrent.accept.result', async function () {
+      this.timeout(60000)
 
-    {
-      const { data: videoImports } = await servers[0].imports.getMyVideoImports()
+      let videoImportId: number
 
-      const videoImport = videoImports.find(i => i.id === videoImportId)
+      {
+        const attributes = {
+          name: 'title with bad word',
+          privacy: VideoPrivacy.PUBLIC,
+          channelId: servers[0].store.channel.id,
+          torrentfile: 'video-720p.torrent' as any
+        }
+        const body = await servers[0].imports.importVideo({ attributes })
+        videoImportId = body.id
+      }
 
-      expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
-      expect(videoImport.state.label).to.equal('Rejected')
-    }
-  })
+      await waitJobs(servers)
+
+      {
+        const { data: videoImports } = await servers[0].imports.getMyVideoImports()
+
+        const videoImport = videoImports.find(i => i.id === videoImportId)
 
-  it('Should run filter:api.video-thread.create.accept.result', async function () {
-    await servers[0].comments.createThread({
-      videoId: videoUUID,
-      text: 'comment with bad word',
-      expectedStatus: HttpStatusCode.FORBIDDEN_403
+        expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
+        expect(videoImport.state.label).to.equal('Rejected')
+      }
     })
   })
 
-  it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
-    const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
-    threadId = created.id
+  describe('Video comments accept', function () {
 
-    await servers[0].comments.addReply({
-      videoId: videoUUID,
-      toCommentId: threadId,
-      text: 'comment with bad word',
-      expectedStatus: HttpStatusCode.FORBIDDEN_403
+    it('Should run filter:api.video-thread.create.accept.result', async function () {
+      await servers[0].comments.createThread({
+        videoId: videoUUID,
+        text: 'comment with bad word',
+        expectedStatus: HttpStatusCode.FORBIDDEN_403
+      })
     })
-    await servers[0].comments.addReply({
-      videoId: videoUUID,
-      toCommentId: threadId,
-      text: 'comment with good word',
-      expectedStatus: HttpStatusCode.OK_200
+
+    it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
+      const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
+      threadId = created.id
+
+      await servers[0].comments.addReply({
+        videoId: videoUUID,
+        toCommentId: threadId,
+        text: 'comment with bad word',
+        expectedStatus: HttpStatusCode.FORBIDDEN_403
+      })
+      await servers[0].comments.addReply({
+        videoId: videoUUID,
+        toCommentId: threadId,
+        text: 'comment with good word',
+        expectedStatus: HttpStatusCode.OK_200
+      })
     })
-  })
 
-  it('Should run filter:api.video-threads.list.params', async function () {
-    const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
+    it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a thread creation', async function () {
+      this.timeout(30000)
 
-    // our plugin do +1 to the count parameter
-    expect(data).to.have.lengthOf(1)
-  })
+      await servers[1].comments.createThread({ videoId: videoUUID, text: 'comment with bad word' })
 
-  it('Should run filter:api.video-threads.list.result', async function () {
-    const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
+      await waitJobs(servers)
 
-    // Plugin do +1 to the total result
-    expect(total).to.equal(2)
-  })
+      {
+        const thread = await servers[0].comments.listThreads({ videoId: videoUUID })
+        expect(thread.data).to.have.lengthOf(1)
+        expect(thread.data[0].text).to.not.include(' bad ')
+      }
+
+      {
+        const thread = await servers[1].comments.listThreads({ videoId: videoUUID })
+        expect(thread.data).to.have.lengthOf(2)
+      }
+    })
 
-  it('Should run filter:api.video-thread-comments.list.params')
+    it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a reply creation', async function () {
+      this.timeout(30000)
 
-  it('Should run filter:api.video-thread-comments.list.result', async function () {
-    const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
+      const { data } = await servers[1].comments.listThreads({ videoId: videoUUID })
+      const threadIdServer2 = data.find(t => t.text === 'thread').id
 
-    expect(thread.comment.text.endsWith(' <3')).to.be.true
+      await servers[1].comments.addReply({
+        videoId: videoUUID,
+        toCommentId: threadIdServer2,
+        text: 'comment with bad word'
+      })
+
+      await waitJobs(servers)
+
+      {
+        const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
+        expect(tree.children).to.have.lengthOf(1)
+        expect(tree.children[0].comment.text).to.not.include(' bad ')
+      }
+
+      {
+        const tree = await servers[1].comments.getThread({ videoId: videoUUID, threadId: threadIdServer2 })
+        expect(tree.children).to.have.lengthOf(2)
+      }
+    })
   })
 
-  it('Should run filter:api.overviews.videos.list.{params,result}', async function () {
-    await servers[0].overviews.getVideos({ page: 1 })
+  describe('Video comments', function () {
+
+    it('Should run filter:api.video-threads.list.params', async function () {
+      const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
+
+      // our plugin do +1 to the count parameter
+      expect(data).to.have.lengthOf(1)
+    })
 
-    // 3 because we get 3 samples per page
-    await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3)
-    await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3)
+    it('Should run filter:api.video-threads.list.result', async function () {
+      const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
+
+      // Plugin do +1 to the total result
+      expect(total).to.equal(2)
+    })
+
+    it('Should run filter:api.video-thread-comments.list.params')
+
+    it('Should run filter:api.video-thread-comments.list.result', async function () {
+      const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
+
+      expect(thread.comment.text.endsWith(' <3')).to.be.true
+    })
+
+    it('Should run filter:api.overviews.videos.list.{params,result}', async function () {
+      await servers[0].overviews.getVideos({ page: 1 })
+
+      // 3 because we get 3 samples per page
+      await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3)
+      await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3)
+    })
   })
 
   describe('filter:video.auto-blacklist.result', function () {
index 5bf01c4b47dc46c659d83a7575cd4619cd8c0c7b..f11d2050b0699abfa69ccac4cfa64899a495f88d 100644 (file)
@@ -103,7 +103,9 @@ export const serverFilterHookObject = {
   'filter:job-queue.process.result': true,
 
   'filter:transcoding.manual.resolutions-to-transcode.result': true,
-  'filter:transcoding.auto.resolutions-to-transcode.result': true
+  'filter:transcoding.auto.resolutions-to-transcode.result': true,
+
+  'filter:activity-pub.remote-video-comment.create.accept.result': true
 }
 
 export type ServerFilterHookName = keyof typeof serverFilterHookObject