aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-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
4 files changed, 30 insertions, 1 deletions
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