From 00494d6e2ae915741f47869dcd359d9728a0af91 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sat, 27 Jun 2020 13:12:30 +0200 Subject: allow limiting video-comments rss feeds to an account or video channel --- server/models/video/video-comment.ts | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'server/models/video/video-comment.ts') diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 091cc2a88..c465eb3e7 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -427,8 +427,31 @@ export class VideoCommentModel extends Model { return VideoCommentModel.findAndCountAll(query) } - static async listForFeed (start: number, count: number, videoId?: number): Promise { + static async listForFeed (parameters: { + start: number + count: number + videoId?: number + accountId?: number + videoChannelId?: number + }): Promise { const serverActor = await getServerActor() + const { start, count, videoId, accountId, videoChannelId } = parameters + + const accountExclusion = { + [Op.notIn]: Sequelize.literal( + '(' + buildBlockedAccountSQL([ serverActor.Account.id, '"Video->VideoChannel"."accountId"' ]) + ')' + ) + } + const accountWhere = accountId + ? { + [Op.and]: { + ...accountExclusion, + [Op.eq]: accountId + } + } + : accountExclusion + + const videoChannelWhere = videoChannelId ? { id: videoChannelId } : undefined const query = { order: [ [ 'createdAt', 'DESC' ] ] as Order, @@ -436,11 +459,7 @@ export class VideoCommentModel extends Model { limit: count, where: { deletedAt: null, - accountId: { - [Op.notIn]: Sequelize.literal( - '(' + buildBlockedAccountSQL([ serverActor.Account.id, '"Video->VideoChannel"."accountId"' ]) + ')' - ) - } + accountId: accountWhere }, include: [ { @@ -454,7 +473,8 @@ export class VideoCommentModel extends Model { { attributes: [ 'accountId' ], model: VideoChannelModel.unscoped(), - required: true + required: true, + where: videoChannelWhere } ] } -- cgit v1.2.3