aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-12 11:05:11 +0200
committerChocobozzz <me@florianbigard.com>2022-08-16 10:33:27 +0200
commit0e6cd1c00f71554fe7375a96db693a6983951ba6 (patch)
treebe9b049e047895c88c561202377f6c5e64ae40df
parent045224d5eb6a41081186c4040bab1570b9d9ad65 (diff)
downloadPeerTube-0e6cd1c00f71554fe7375a96db693a6983951ba6.tar.gz
PeerTube-0e6cd1c00f71554fe7375a96db693a6983951ba6.tar.zst
PeerTube-0e6cd1c00f71554fe7375a96db693a6983951ba6.zip
Add ability to list comments on local videos
-rw-r--r--client/src/app/+admin/overview/comments/video-comment-list.component.ts4
-rw-r--r--client/src/app/shared/shared-video-comment/video-comment.service.ts4
-rw-r--r--server/controllers/api/videos/comment.ts1
-rw-r--r--server/middlewares/validators/videos/video-comments.ts6
-rw-r--r--server/models/video/video-comment.ts8
-rw-r--r--server/tests/api/videos/video-comments.ts16
-rw-r--r--shared/server-commands/videos/comments-command.ts3
7 files changed, 40 insertions, 2 deletions
diff --git a/client/src/app/+admin/overview/comments/video-comment-list.component.ts b/client/src/app/+admin/overview/comments/video-comment-list.component.ts
index f01a1629b..cfe40b92a 100644
--- a/client/src/app/+admin/overview/comments/video-comment-list.component.ts
+++ b/client/src/app/+admin/overview/comments/video-comment-list.component.ts
@@ -54,6 +54,10 @@ export class VideoCommentListComponent extends RestTable implements OnInit {
54 { 54 {
55 value: 'local:false', 55 value: 'local:false',
56 label: $localize`Remote comments` 56 label: $localize`Remote comments`
57 },
58 {
59 value: 'localVideo:true',
60 label: $localize`Comments on local videos`
57 } 61 }
58 ] 62 ]
59 } 63 }
diff --git a/client/src/app/shared/shared-video-comment/video-comment.service.ts b/client/src/app/shared/shared-video-comment/video-comment.service.ts
index 8cd94643a..8d2deedf7 100644
--- a/client/src/app/shared/shared-video-comment/video-comment.service.ts
+++ b/client/src/app/shared/shared-video-comment/video-comment.service.ts
@@ -190,6 +190,10 @@ export class VideoCommentService {
190 prefix: 'local:', 190 prefix: 'local:',
191 isBoolean: true 191 isBoolean: true
192 }, 192 },
193 onLocalVideo: {
194 prefix: 'localVideo:',
195 isBoolean: true
196 },
193 197
194 searchAccount: { prefix: 'account:' }, 198 searchAccount: { prefix: 'account:' },
195 searchVideo: { prefix: 'video:' } 199 searchVideo: { prefix: 'video:' }
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index 47fa2f2e2..44d64776c 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -91,6 +91,7 @@ async function listComments (req: express.Request, res: express.Response) {
91 sort: req.query.sort, 91 sort: req.query.sort,
92 92
93 isLocal: req.query.isLocal, 93 isLocal: req.query.isLocal,
94 onLocalVideo: req.query.onLocalVideo,
94 search: req.query.search, 95 search: req.query.search,
95 searchAccount: req.query.searchAccount, 96 searchAccount: req.query.searchAccount,
96 searchVideo: req.query.searchVideo 97 searchVideo: req.query.searchVideo
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts
index b22a4e3b7..68f41e50e 100644
--- a/server/middlewares/validators/videos/video-comments.ts
+++ b/server/middlewares/validators/videos/video-comments.ts
@@ -24,6 +24,12 @@ const listVideoCommentsValidator = [
24 .custom(isBooleanValid) 24 .custom(isBooleanValid)
25 .withMessage('Should have a valid is local boolean'), 25 .withMessage('Should have a valid is local boolean'),
26 26
27 query('onLocalVideo')
28 .optional()
29 .customSanitizer(toBooleanOrNull)
30 .custom(isBooleanValid)
31 .withMessage('Should have a valid is on local video boolean'),
32
27 query('search') 33 query('search')
28 .optional() 34 .optional()
29 .custom(exists).withMessage('Should have a valid search'), 35 .custom(exists).withMessage('Should have a valid search'),
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 6c5a764bf..1195e47e9 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -14,6 +14,7 @@ import {
14 Table, 14 Table,
15 UpdatedAt 15 UpdatedAt
16} from 'sequelize-typescript' 16} from 'sequelize-typescript'
17import { exists } from '@server/helpers/custom-validators/misc'
17import { getServerActor } from '@server/models/application/application' 18import { getServerActor } from '@server/models/application/application'
18import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' 19import { MAccount, MAccountId, MUserAccountId } from '@server/types/models'
19import { VideoPrivacy } from '@shared/models' 20import { VideoPrivacy } from '@shared/models'
@@ -312,12 +313,13 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
312 count: number 313 count: number
313 sort: string 314 sort: string
314 315
316 onLocalVideo?: boolean
315 isLocal?: boolean 317 isLocal?: boolean
316 search?: string 318 search?: string
317 searchAccount?: string 319 searchAccount?: string
318 searchVideo?: string 320 searchVideo?: string
319 }) { 321 }) {
320 const { start, count, sort, isLocal, search, searchAccount, searchVideo } = parameters 322 const { start, count, sort, isLocal, search, searchAccount, searchVideo, onLocalVideo } = parameters
321 323
322 const where: WhereOptions = { 324 const where: WhereOptions = {
323 deletedAt: null 325 deletedAt: null
@@ -363,6 +365,10 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
363 Object.assign(whereVideo, searchAttribute(searchVideo, 'name')) 365 Object.assign(whereVideo, searchAttribute(searchVideo, 'name'))
364 } 366 }
365 367
368 if (exists(onLocalVideo)) {
369 Object.assign(whereVideo, { remote: !onLocalVideo })
370 }
371
366 const getQuery = (forCount: boolean) => { 372 const getQuery = (forCount: boolean) => {
367 return { 373 return {
368 offset: start, 374 offset: start,
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index 1488ce2b5..5ab401aa4 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -254,6 +254,22 @@ describe('Test video comments', function () {
254 expect(total).to.equal(0) 254 expect(total).to.equal(0)
255 }) 255 })
256 256
257 it('Should filter instance comments by onLocalVideo', async function () {
258 {
259 const { total, data } = await command.listForAdmin({ onLocalVideo: false })
260
261 expect(data).to.have.lengthOf(0)
262 expect(total).to.equal(0)
263 }
264
265 {
266 const { total, data } = await command.listForAdmin({ onLocalVideo: true })
267
268 expect(data).to.not.have.lengthOf(0)
269 expect(total).to.not.equal(0)
270 }
271 })
272
257 it('Should search instance comments by account', async function () { 273 it('Should search instance comments by account', async function () {
258 const { total, data } = await command.listForAdmin({ searchAccount: 'user' }) 274 const { total, data } = await command.listForAdmin({ searchAccount: 'user' })
259 275
diff --git a/shared/server-commands/videos/comments-command.ts b/shared/server-commands/videos/comments-command.ts
index f0d163a07..156cf452f 100644
--- a/shared/server-commands/videos/comments-command.ts
+++ b/shared/server-commands/videos/comments-command.ts
@@ -14,6 +14,7 @@ export class CommentsCommand extends AbstractCommand {
14 count?: number 14 count?: number
15 sort?: string 15 sort?: string
16 isLocal?: boolean 16 isLocal?: boolean
17 onLocalVideo?: boolean
17 search?: string 18 search?: string
18 searchAccount?: string 19 searchAccount?: string
19 searchVideo?: string 20 searchVideo?: string
@@ -21,7 +22,7 @@ export class CommentsCommand extends AbstractCommand {
21 const { sort = '-createdAt' } = options 22 const { sort = '-createdAt' } = options
22 const path = '/api/v1/videos/comments' 23 const path = '/api/v1/videos/comments'
23 24
24 const query = { sort, ...pick(options, [ 'start', 'count', 'isLocal', 'search', 'searchAccount', 'searchVideo' ]) } 25 const query = { sort, ...pick(options, [ 'start', 'count', 'isLocal', 'onLocalVideo', 'search', 'searchAccount', 'searchVideo' ]) }
25 26
26 return this.getRequestBody<ResultList<VideoComment>>({ 27 return this.getRequestBody<ResultList<VideoComment>>({
27 ...options, 28 ...options,