Fix comments deleted display
authorChocobozzz <me@florianbigard.com>
Tue, 19 May 2020 08:48:50 +0000 (10:48 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Fri, 29 May 2020 07:21:26 +0000 (09:21 +0200)
server/controllers/api/videos/comment.ts
server/models/video/video-comment.ts
server/tests/api/users/blocklist.ts

index bdd3cf9e27334a1689d2b4ea543375b613e4bcb0..2dcb85ecf6a4f8ff77d412320e0ac24a57550fbc 100644 (file)
@@ -178,5 +178,5 @@ async function removeVideoComment (req: express.Request, res: express.Response)
 
   auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON()))
 
-  return res.type('json').status(204)
+  return res.type('json').status(204).end()
 }
index 7c890ce6dab569e166b50a56812bfcf4346e0cda..dfeb1c4e79d2b8c8281d76f714ba023a0fb7e51f 100644 (file)
@@ -24,13 +24,14 @@ import {
   MCommentOwnerVideoReply
 } from '../../typings/models/video'
 import { AccountModel } from '../account/account'
-import { ActorModel } from '../activitypub/actor'
+import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor'
 import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
 import { VideoChannelModel } from './video-channel'
 
 enum ScopeNames {
   WITH_ACCOUNT = 'WITH_ACCOUNT',
+  WITH_ACCOUNT_FOR_API = 'WITH_ACCOUNT_FOR_API',
   WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO',
   WITH_VIDEO = 'WITH_VIDEO',
   ATTRIBUTES_FOR_API = 'ATTRIBUTES_FOR_API'
@@ -82,6 +83,22 @@ enum ScopeNames {
       }
     ]
   },
+  [ScopeNames.WITH_ACCOUNT_FOR_API]: {
+    include: [
+      {
+        model: AccountModel.unscoped(),
+        include: [
+          {
+            attributes: {
+              exclude: unusedActorAttributesForAPI
+            },
+            model: ActorModel, // Default scope includes avatar and server
+            required: true
+          }
+        ]
+      }
+    ]
+  },
   [ScopeNames.WITH_IN_REPLY_TO]: {
     include: [
       {
@@ -275,18 +292,33 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
       limit: count,
       order: getCommentSort(sort),
       where: {
-        videoId,
-        inReplyToCommentId: null,
-        accountId: {
-          [Op.notIn]: Sequelize.literal(
-            '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')'
-          )
-        }
+        [Op.and]: [
+          {
+            videoId
+          },
+          {
+            inReplyToCommentId: null
+          },
+          {
+            [Op.or]: [
+              {
+                accountId: {
+                  [Op.notIn]: Sequelize.literal(
+                    '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')'
+                  )
+                }
+              },
+              {
+                accountId: null
+              }
+            ]
+          }
+        ]
       }
     }
 
     const scopes: (string | ScopeOptions)[] = [
-      ScopeNames.WITH_ACCOUNT,
+      ScopeNames.WITH_ACCOUNT_FOR_API,
       {
         method: [ ScopeNames.ATTRIBUTES_FOR_API, serverAccountId, userAccountId ]
       }
@@ -328,7 +360,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
     }
 
     const scopes: any[] = [
-      ScopeNames.WITH_ACCOUNT,
+      ScopeNames.WITH_ACCOUNT_FOR_API,
       {
         method: [ ScopeNames.ATTRIBUTES_FOR_API, serverAccountId, userAccountId ]
       }
index 21b9ae4f801b8b70b307eef763bce01cfe57a456..e37dbb5a411778aee9542586ce522135113e2d9e 100644 (file)
@@ -195,7 +195,7 @@ describe('Test blocklist', function () {
       })
 
       it('Should hide its comments', async function () {
-        const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5, '-createdAt', servers[0].accessToken)
+        const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 25, '-createdAt', servers[0].accessToken)
 
         const threads: VideoComment[] = resThreads.body.data
         expect(threads).to.have.lengthOf(1)
@@ -467,9 +467,11 @@ describe('Test blocklist', function () {
 
       it('Should hide its comments', async function () {
         for (const token of [ userModeratorToken, servers[0].accessToken ]) {
-          const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5, '-createdAt', token)
+          const resThreads = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 20, '-createdAt', token)
+
+          let threads: VideoComment[] = resThreads.body.data
+          threads = threads.filter(t => t.isDeleted === false)
 
-          const threads: VideoComment[] = resThreads.body.data
           expect(threads).to.have.lengthOf(1)
           expect(threads[0].totalReplies).to.equal(0)