From 5fb2e2888ce032c638e4b75d07458642f0833e52 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 May 2020 16:16:24 +0200 Subject: First implem global search --- server/models/account/account-blocklist.ts | 38 ++++++++++++++++++++++++++++++ server/models/server/server-blocklist.ts | 21 +++++++++++++++++ 2 files changed, 59 insertions(+) (limited to 'server/models') diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts index d8a7ce4b4..2c6b756d2 100644 --- a/server/models/account/account-blocklist.ts +++ b/server/models/account/account-blocklist.ts @@ -5,6 +5,8 @@ import { AccountBlock } from '../../../shared/models/blocklist' import { Op } from 'sequelize' import * as Bluebird from 'bluebird' import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models' +import { ActorModel } from '../activitypub/actor' +import { ServerModel } from '../server/server' enum ScopeNames { WITH_ACCOUNTS = 'WITH_ACCOUNTS' @@ -149,6 +151,42 @@ export class AccountBlocklistModel extends Model { }) } + static listHandlesBlockedBy (accountIds: number[]): Bluebird { + const query = { + attributes: [], + where: { + accountId: { + [Op.in]: accountIds + } + }, + include: [ + { + attributes: [ 'id' ], + model: AccountModel.unscoped(), + required: true, + as: 'BlockedAccount', + include: [ + { + attributes: [ 'preferredUsername' ], + model: ActorModel.unscoped(), + required: true, + include: [ + { + attributes: [ 'host' ], + model: ServerModel.unscoped(), + required: true + } + ] + } + ] + } + ] + } + + return AccountBlocklistModel.findAll(query) + .then(entries => entries.map(e => `${e.BlockedAccount.Actor.preferredUsername}@${e.BlockedAccount.Actor.Server.host}`)) + } + toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock { return { byAccount: this.ByAccount.toFormattedJSON(), diff --git a/server/models/server/server-blocklist.ts b/server/models/server/server-blocklist.ts index 892024c04..ad8e3d1e8 100644 --- a/server/models/server/server-blocklist.ts +++ b/server/models/server/server-blocklist.ts @@ -120,6 +120,27 @@ export class ServerBlocklistModel extends Model { return ServerBlocklistModel.findOne(query) } + static listHostsBlockedBy (accountIds: number[]): Bluebird { + const query = { + attributes: [ ], + where: { + accountId: { + [Op.in]: accountIds + } + }, + include: [ + { + attributes: [ 'host' ], + model: ServerModel.unscoped(), + required: true + } + ] + } + + return ServerBlocklistModel.findAll(query) + .then(entries => entries.map(e => e.BlockedServer.host)) + } + static listForApi (parameters: { start: number count: number -- cgit v1.2.3