+ static listHandlesBlockedBy (accountIds: number[]): Promise<string[]> {
+ const query = {
+ attributes: [ 'id' ],
+ 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}`))
+ }
+
+ static getBlockStatus (byAccountIds: number[], handles: string[]): Promise<{ name: string, host: string, accountId: number }[]> {
+ const sanitizedHandles = handlesToNameAndHost(handles)
+
+ const localHandles = sanitizedHandles.filter(h => !h.host)
+ .map(h => h.name)
+
+ const remoteHandles = sanitizedHandles.filter(h => !!h.host)
+ .map(h => ([ h.name, h.host ]))
+
+ const handlesWhere: string[] = []
+
+ if (localHandles.length !== 0) {
+ handlesWhere.push(`("actor"."preferredUsername" IN (:localHandles) AND "server"."id" IS NULL)`)
+ }
+
+ if (remoteHandles.length !== 0) {
+ handlesWhere.push(`(("actor"."preferredUsername", "server"."host") IN (:remoteHandles))`)
+ }
+
+ const rawQuery = `SELECT "accountBlocklist"."accountId", "actor"."preferredUsername" AS "name", "server"."host" ` +
+ `FROM "accountBlocklist" ` +
+ `INNER JOIN "account" ON "account"."id" = "accountBlocklist"."targetAccountId" ` +
+ `INNER JOIN "actor" ON "actor"."id" = "account"."actorId" ` +
+ `LEFT JOIN "server" ON "server"."id" = "actor"."serverId" ` +
+ `WHERE "accountBlocklist"."accountId" IN (${createSafeIn(AccountBlocklistModel.sequelize, byAccountIds)}) ` +
+ `AND (${handlesWhere.join(' OR ')})`
+
+ return AccountBlocklistModel.sequelize.query(rawQuery, {
+ type: QueryTypes.SELECT as QueryTypes.SELECT,
+ replacements: { byAccountIds, localHandles, remoteHandles }
+ })
+ }
+