From e0a929179a9dc76e035ca7fda2b61d5ff46afbc5 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sun, 19 Apr 2020 14:11:40 +0200 Subject: Add filter inputs for blacklisted videos and muted accounts/servers --- server/models/account/account-blocklist.ts | 32 ++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'server/models/account') diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts index e2f66d733..fe2d5d010 100644 --- a/server/models/account/account-blocklist.ts +++ b/server/models/account/account-blocklist.ts @@ -1,6 +1,6 @@ import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { AccountModel } from './account' -import { getSort } from '../utils' +import { getSort, searchAttribute } from '../utils' import { AccountBlock } from '../../../shared/models/blocklist' import { Op } from 'sequelize' import * as Bluebird from 'bluebird' @@ -111,16 +111,36 @@ export class AccountBlocklistModel extends Model { return AccountBlocklistModel.findOne(query) } - static listForApi (accountId: number, start: number, count: number, sort: string) { + static listForApi (parameters: { + start: number + count: number + sort: string + search?: string + accountId: number + }) { + const { start, count, sort, search, accountId } = parameters + const query = { offset: start, limit: count, - order: getSort(sort), - where: { - accountId - } + order: getSort(sort) + } + + const where = { + accountId } + if (search) { + Object.assign(where, { + [Op.or]: [ + { ...searchAttribute(search, '$BlockedAccount.name$') }, + { ...searchAttribute(search, '$BlockedAccount.Actor.url$') } + ] + }) + } + + Object.assign(query, { where }) + return AccountBlocklistModel .scope([ ScopeNames.WITH_ACCOUNTS ]) .findAndCountAll(query) -- cgit v1.2.3