Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add mute filter to comment list

Chocobozzz74f0f4e035cd
diff --git a/client/src/app/+admin/overview/comments/video-comment-list.component.html b/client/src/app/+admin/overview/comments/video-comment-list.component.html
index 412f9502f1..13982a536b 100644
--- a/client/src/app/+admin/overview/comments/video-comment-list.component.html
+++ b/client/src/app/+admin/overview/comments/video-comment-list.component.html
@@ -1,4 +1 @@
-<em i18n>This view also shows comments from muted accounts.</em>
-
<my-video-comment-list-admin-owner mode="admin" key="AdminVideoCommentList"></my-video-comment-list-admin-owner>
-
diff --git a/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.ts b/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.ts
index 1a0f3d5c31..204c9ccbbc 100644
--- a/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.ts
+++ b/client/src/app/shared/shared-video-comment/video-comment-list-admin-owner.component.ts
@@ -244,6 +244,17 @@ export class VideoCommentListAdminOwnerComponent implements OnInit, OnDestroy {
{ value: false, label: $localize`Remote` }
]
},
+
+ {
+ type: 'title',
+ title: $localize`Moderation`
+ },
+ {
+ type: 'checkbox',
+ key: 'includeMuted',
+ label: $localize`Include comments from muted accounts`
+ },
+
{
type: 'title',
title: $localize`Commented video scope`
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 8e3712c979..c5175863cb 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
@@ -102,9 +102,10 @@ export class VideoCommentService {
options: Parameters<VideoCommentService['buildAdminVideoCommentsParams']>[0] & {
isLocal?: boolean
onLocalVideo?: boolean
+ includeMuted?: boolean
}
): Observable<ResultList<VideoCommentForAdminOrUser>> {
- const { isLocal, onLocalVideo } = options
+ const { isLocal, onLocalVideo, includeMuted } = options
const url = VideoCommentService.BASE_VIDEO_URL + 'comments'
@@ -118,6 +119,10 @@ export class VideoCommentService {
params = params.set('onLocalVideo', '' + onLocalVideo)
}
+ if (includeMuted !== undefined) {
+ params = params.set('includeMuted', '' + includeMuted)
+ }
+
return this.authHttp.get<ResultList<VideoCommentForAdminOrUser>>(url, { params })
.pipe(
catchError(res => this.restExtractor.handleError(res))
diff --git a/packages/server-commands/src/videos/comments-command.ts b/packages/server-commands/src/videos/comments-command.ts
index dcf49b21bc..25b4ce318c 100644
--- a/packages/server-commands/src/videos/comments-command.ts
+++ b/packages/server-commands/src/videos/comments-command.ts
@@ -30,12 +30,13 @@ export class CommentsCommand extends AbstractCommand {
listForAdmin (options: OverrideCommandOptions & ListForAdminOrAccountCommonOptions & {
isLocal?: boolean
onLocalVideo?: boolean
+ includeMuted?: boolean
} = {}) {
const path = '/api/v1/videos/comments'
const query = {
...this.buildListForAdminOrAccountQuery(options),
- ...pick(options, [ 'isLocal', 'onLocalVideo' ])
+ ...pick(options, [ 'isLocal', 'onLocalVideo', 'includeMuted' ])
}
return this.getRequestBody<ResultList<VideoCommentForAdminOrUser>>({
diff --git a/packages/tests/src/api/check-params/video-comments.ts b/packages/tests/src/api/check-params/video-comments.ts
index 5f37ce87d5..fb371ccdb4 100644
--- a/packages/tests/src/api/check-params/video-comments.ts
+++ b/packages/tests/src/api/check-params/video-comments.ts
@@ -507,7 +507,8 @@ describe('Test video comments API validator', function () {
searchVideo: 'toto',
videoId: video.uuid,
videoChannelId: server.store.channel.id,
- autoTagOneOf: [ 'external-link' ]
+ autoTagOneOf: [ 'external-link' ],
+ includeMuted: false
}
await server.comments.listForAdmin({ ...base, isLocal: false })
diff --git a/packages/tests/src/api/videos/video-comments.ts b/packages/tests/src/api/videos/video-comments.ts
index e805c6a1ea..6580e9087f 100644
--- a/packages/tests/src/api/videos/video-comments.ts
+++ b/packages/tests/src/api/videos/video-comments.ts
@@ -1,6 +1,6 @@
/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import { VideoCreateResult } from '@peertube/peertube-models'
+import { VideoCommentForAdminOrUser, VideoCreateResult } from '@peertube/peertube-models'
import {
CommentsCommand,
PeerTubeServer,
@@ -315,6 +315,43 @@ describe('Test video comments', function () {
}
})
+ it('Should filter instance comments by includeMuted', async function () {
+ await server.blocklist.addToServerBlocklist({ account: 'user1@' + server.host })
+
+ const findUserComment = (data: VideoCommentForAdminOrUser[]) => data.find(c => c.account.name === 'user1')
+
+ {
+ const { total, data } = await command.listForAdmin({ includeMuted: false })
+
+ expect(total).to.be.greaterThan(0)
+ expect(data).to.have.lengthOf(total)
+
+ expect(findUserComment(data)).to.not.exist
+ }
+
+ {
+ const { total, data } = await command.listForAdmin({ includeMuted: true })
+
+ expect(total).to.be.greaterThan(0)
+ expect(data).to.have.lengthOf(total)
+
+ expect(findUserComment(data)).to.exist
+ }
+
+ // Default is false
+
+ {
+ const { total, data } = await command.listForAdmin()
+
+ expect(total).to.be.greaterThan(0)
+ expect(data).to.have.lengthOf(total)
+
+ expect(findUserComment(data)).to.not.exist
+ }
+
+ await server.blocklist.removeFromServerBlocklist({ account: 'user1@' + server.host })
+ })
+
it('Should search comments by account', async function () {
for (const fn of listFunctions()) {
const { total, data } = await fn({ searchAccount: 'user' })
diff --git a/server/core/controllers/api/videos/comment.ts b/server/core/controllers/api/videos/comment.ts
index 0b0a31b855..506dc9ba05 100644
--- a/server/core/controllers/api/videos/comment.ts
+++ b/server/core/controllers/api/videos/comment.ts
@@ -106,6 +106,12 @@ export {
// ---------------------------------------------------------------------------
async function listComments (req: express.Request, res: express.Response) {
+ const serverActor = await getServerActor()
+
+ const blockerAccountIds = req.query.includeMuted !== true
+ ? await VideoCommentModel.buildBlockerAccountIds({ user: null })
+ : undefined
+
const options = {
...pick(req.query, [
'start',
@@ -121,7 +127,8 @@ async function listComments (req: express.Request, res: express.Response) {
videoId: res.locals.videoImmutable?.id,
videoChannelOwnerId: res.locals.videoChannel?.id,
- autoTagOfAccountId: (await getServerActor()).Account.id,
+ autoTagOfAccountId: serverActor.Account.id,
+ blockerAccountIds,
heldForReview: undefined
}
diff --git a/server/core/middlewares/validators/videos/video-comments.ts b/server/core/middlewares/validators/videos/video-comments.ts
index b1d9588d1e..b15ae853ae 100644
--- a/server/core/middlewares/validators/videos/video-comments.ts
+++ b/server/core/middlewares/validators/videos/video-comments.ts
@@ -388,6 +388,12 @@ function getCommonVideoCommentsValidators () {
query('autoTagOneOf')
.optional()
.customSanitizer(toArray)
- .custom(isStringArray).withMessage('Should have a valid autoTagOneOf array')
+ .custom(isStringArray).withMessage('Should have a valid autoTagOneOf array'),
+
+ query('includeMuted')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid)
+ .withMessage('Should have a valid includeMuted boolean')
]
}
diff --git a/server/core/models/video/video-comment.ts b/server/core/models/video/video-comment.ts
index 9ccea23ae3..664f3e69c5 100644
--- a/server/core/models/video/video-comment.ts
+++ b/server/core/models/video/video-comment.ts
@@ -346,6 +346,8 @@ export class VideoCommentModel extends SequelizeModel<VideoCommentModel> {
videoId?: number
videoChannelId?: number
autoTagOneOf?: string[]
+
+ blockerAccountIds?: number[]
}) {
const queryOptions: ListVideoCommentsOptions = {
...pick(parameters, [
@@ -364,7 +366,8 @@ export class VideoCommentModel extends SequelizeModel<VideoCommentModel> {
'videoAccountOwnerId',
'videoAccountOwnerIncludeCollaborations',
'videoChannelOwnerId',
- 'heldForReview'
+ 'heldForReview',
+ 'blockerAccountIds'
]),
selectType: 'api-list',
@@ -808,8 +811,8 @@ export class VideoCommentModel extends SequelizeModel<VideoCommentModel> {
}
}
- private static async buildBlockerAccountIds (options: {
- user: MUserAccountId
+ static async buildBlockerAccountIds (options: {
+ user: MUserAccountId | null
}): Promise<number[]> {
const { user } = options
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index 9aac74aef8..2dad05d0d3 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -6304,6 +6304,7 @@ paths:
- $ref: '#/components/parameters/autoTagOneOfComment'
- $ref: '#/components/parameters/isLocal'
- $ref: '#/components/parameters/onLocalVideo'
+ - $ref: '#/components/parameters/includeMuted'
responses:
'200':
@@ -9122,6 +9123,13 @@ components:
schema:
type: boolean
description: 'Display only objects of local or remote videos'
+ includeMuted:
+ name: includeMuted
+ in: query
+ required: false
+ schema:
+ type: boolean
+ description: '**PeerTube >= 8.2** Include comments from muted accounts'
videoChannelId:
name: videoChannelId
in: query