]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add ability to list comments on local videos
authorChocobozzz <me@florianbigard.com>
Fri, 12 Aug 2022 09:05:11 +0000 (11:05 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 16 Aug 2022 08:33:27 +0000 (10:33 +0200)
client/src/app/+admin/overview/comments/video-comment-list.component.ts
client/src/app/shared/shared-video-comment/video-comment.service.ts
server/controllers/api/videos/comment.ts
server/middlewares/validators/videos/video-comments.ts
server/models/video/video-comment.ts
server/tests/api/videos/video-comments.ts
shared/server-commands/videos/comments-command.ts

index f01a1629b6c92fb48bf64353a4c63dbd63ddefbc..cfe40b92a36da822b728718992ec3e9143c51b43 100644 (file)
@@ -54,6 +54,10 @@ export class VideoCommentListComponent extends RestTable implements OnInit {
         {
           value: 'local:false',
           label: $localize`Remote comments`
+        },
+        {
+          value: 'localVideo:true',
+          label: $localize`Comments on local videos`
         }
       ]
     }
index 8cd94643a41404c0f2e5ed5ceb9bfe17b57379c1..8d2deedf7f945782ced8ad98636c8a43a87cbce3 100644 (file)
@@ -190,6 +190,10 @@ export class VideoCommentService {
         prefix: 'local:',
         isBoolean: true
       },
+      onLocalVideo: {
+        prefix: 'localVideo:',
+        isBoolean: true
+      },
 
       searchAccount: { prefix: 'account:' },
       searchVideo: { prefix: 'video:' }
index 47fa2f2e20b2d5ec43221b655d624bccae6a6048..44d64776c60a351232c4ea9b3cf547a2f3c28b81 100644 (file)
@@ -91,6 +91,7 @@ async function listComments (req: express.Request, res: express.Response) {
     sort: req.query.sort,
 
     isLocal: req.query.isLocal,
+    onLocalVideo: req.query.onLocalVideo,
     search: req.query.search,
     searchAccount: req.query.searchAccount,
     searchVideo: req.query.searchVideo
index b22a4e3b79e5a2eb75377d5644d2478537e421b1..68f41e50e5e49ec37fec24409020abb8c00dc9be 100644 (file)
@@ -24,6 +24,12 @@ const listVideoCommentsValidator = [
   .custom(isBooleanValid)
   .withMessage('Should have a valid is local boolean'),
 
+  query('onLocalVideo')
+  .optional()
+  .customSanitizer(toBooleanOrNull)
+  .custom(isBooleanValid)
+  .withMessage('Should have a valid is on local video boolean'),
+
   query('search')
     .optional()
     .custom(exists).withMessage('Should have a valid search'),
index 6c5a764bf217bea8e59431737a7c9754eb569146..1195e47e9d0a093bbf980c41dbbf6cedfba9e130 100644 (file)
@@ -14,6 +14,7 @@ import {
   Table,
   UpdatedAt
 } from 'sequelize-typescript'
+import { exists } from '@server/helpers/custom-validators/misc'
 import { getServerActor } from '@server/models/application/application'
 import { MAccount, MAccountId, MUserAccountId } from '@server/types/models'
 import { VideoPrivacy } from '@shared/models'
@@ -312,12 +313,13 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
     count: number
     sort: string
 
+    onLocalVideo?: boolean
     isLocal?: boolean
     search?: string
     searchAccount?: string
     searchVideo?: string
   }) {
-    const { start, count, sort, isLocal, search, searchAccount, searchVideo } = parameters
+    const { start, count, sort, isLocal, search, searchAccount, searchVideo, onLocalVideo } = parameters
 
     const where: WhereOptions = {
       deletedAt: null
@@ -363,6 +365,10 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
       Object.assign(whereVideo, searchAttribute(searchVideo, 'name'))
     }
 
+    if (exists(onLocalVideo)) {
+      Object.assign(whereVideo, { remote: !onLocalVideo })
+    }
+
     const getQuery = (forCount: boolean) => {
       return {
         offset: start,
index 1488ce2b5a32cbedbac9a51231bc85c443ea48dc..5ab401aa40c8ab395dc4a22a5b2dc75bc3335ede 100644 (file)
@@ -254,6 +254,22 @@ describe('Test video comments', function () {
       expect(total).to.equal(0)
     })
 
+    it('Should filter instance comments by onLocalVideo', async function () {
+      {
+        const { total, data } = await command.listForAdmin({ onLocalVideo: false })
+
+        expect(data).to.have.lengthOf(0)
+        expect(total).to.equal(0)
+      }
+
+      {
+        const { total, data } = await command.listForAdmin({ onLocalVideo: true })
+
+        expect(data).to.not.have.lengthOf(0)
+        expect(total).to.not.equal(0)
+      }
+    })
+
     it('Should search instance comments by account', async function () {
       const { total, data } = await command.listForAdmin({ searchAccount: 'user' })
 
index f0d163a0775f4114abe092cd6fb7a3b15e7569e7..156cf452f1b7c75f8b76bfe73abffa847a9cf599 100644 (file)
@@ -14,6 +14,7 @@ export class CommentsCommand extends AbstractCommand {
     count?: number
     sort?: string
     isLocal?: boolean
+    onLocalVideo?: boolean
     search?: string
     searchAccount?: string
     searchVideo?: string
@@ -21,7 +22,7 @@ export class CommentsCommand extends AbstractCommand {
     const { sort = '-createdAt' } = options
     const path = '/api/v1/videos/comments'
 
-    const query = { sort, ...pick(options, [ 'start', 'count', 'isLocal', 'search', 'searchAccount', 'searchVideo' ]) }
+    const query = { sort, ...pick(options, [ 'start', 'count', 'isLocal', 'onLocalVideo', 'search', 'searchAccount', 'searchVideo' ]) }
 
     return this.getRequestBody<ResultList<VideoComment>>({
       ...options,