From f0a47bc92aa20b91b46197a4d3fc430aea962848 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 29 Aug 2019 14:31:04 +0200 Subject: Hide video abuses from muted accounts --- server/models/video/video-abuse.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index 6ef1a915d..3636db18d 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts @@ -7,12 +7,13 @@ import { isVideoAbuseStateValid } from '../../helpers/custom-validators/video-abuses' import { AccountModel } from '../account/account' -import { getSort, throwIfNotValid } from '../utils' +import { buildBlockedAccountSQL, getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoAbuseState } from '../../../shared' import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' -import { MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models' +import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models' import * as Bluebird from 'bluebird' +import { literal, Op } from 'sequelize' @Table({ tableName: 'videoAbuse', @@ -85,11 +86,25 @@ export class VideoAbuseModel extends Model { return VideoAbuseModel.findOne(query) } - static listForApi (start: number, count: number, sort: string) { + static listForApi (parameters: { + start: number, + count: number, + sort: string, + serverAccountId: number + user?: MUserAccountId + }) { + const { start, count, sort, user, serverAccountId } = parameters + const userAccountId = user ? user.Account.id : undefined + const query = { offset: start, limit: count, order: getSort(sort), + where: { + reporterAccountId: { + [Op.notIn]: literal('(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')') + } + }, include: [ { model: AccountModel, -- cgit v1.2.3