Fix comments feed with musted accounts
authorChocobozzz <me@florianbigard.com>
Wed, 6 May 2020 12:12:12 +0000 (14:12 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 6 May 2020 12:12:12 +0000 (14:12 +0200)
server/models/video/video-comment.ts
server/tests/feeds/feeds.ts

index b7ed6240e25f5c22018676f7535de4bd112b5624..6d60271e62099cfb3f82fbb93dcc0c58de564545 100644 (file)
@@ -381,13 +381,20 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
     return VideoCommentModel.findAndCountAll<MComment>(query)
   }
 
-  static listForFeed (start: number, count: number, videoId?: number): Bluebird<MCommentOwnerVideoFeed[]> {
+  static async listForFeed (start: number, count: number, videoId?: number): Promise<MCommentOwnerVideoFeed[]> {
+    const serverActor = await getServerActor()
+
     const query = {
       order: [ [ 'createdAt', 'DESC' ] ] as Order,
       offset: start,
       limit: count,
       where: {
-        deletedAt: null
+        deletedAt: null,
+        accountId: {
+          [Op.notIn]: Sequelize.literal(
+            '(' + buildBlockedAccountSQL(serverActor.Account.id) + ')'
+          )
+        }
       },
       include: [
         {
index d978123cfc827449b0a22e28ae4da90f74146862..7fac921a319e68ad6e566afdcfbad38547da687f 100644 (file)
@@ -20,6 +20,7 @@ import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-
 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
 import { User } from '../../../shared/models/users'
 import { VideoPrivacy } from '@shared/models'
+import { addAccountToServerBlocklist } from '@shared/extra-utils/users/blocklist'
 
 chai.use(require('chai-xml'))
 chai.use(require('chai-json-schema'))
@@ -216,6 +217,17 @@ describe('Test syndication feeds', () => {
         expect(jsonObj.items[1].html_content).to.equal('super comment 1')
       }
     })
+
+    it('Should not list comments from muted accounts or instances', async function () {
+      await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, 'root@localhost:' + servers[0].port)
+
+      {
+        const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 2 })
+        const jsonObj = JSON.parse(json.text)
+        expect(jsonObj.items.length).to.be.equal(0)
+      }
+
+    })
   })
 
   after(async function () {