aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account-blocklist.ts5
-rw-r--r--server/models/server/server-blocklist.ts26
2 files changed, 26 insertions, 5 deletions
diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts
index 8bcaca828..6ebe32556 100644
--- a/server/models/account/account-blocklist.ts
+++ b/server/models/account/account-blocklist.ts
@@ -75,11 +75,6 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> {
75 }) 75 })
76 BlockedAccount: AccountModel 76 BlockedAccount: AccountModel
77 77
78 static isAccountMutedBy (accountId: number, targetAccountId: number) {
79 return AccountBlocklistModel.isAccountMutedByMulti([ accountId ], targetAccountId)
80 .then(result => result[accountId])
81 }
82
83 static isAccountMutedByMulti (accountIds: number[], targetAccountId: number) { 78 static isAccountMutedByMulti (accountIds: number[], targetAccountId: number) {
84 const query = { 79 const query = {
85 attributes: [ 'accountId', 'id' ], 80 attributes: [ 'accountId', 'id' ],
diff --git a/server/models/server/server-blocklist.ts b/server/models/server/server-blocklist.ts
index 3e9687191..b88df4fd5 100644
--- a/server/models/server/server-blocklist.ts
+++ b/server/models/server/server-blocklist.ts
@@ -5,6 +5,7 @@ import { ServerBlock } from '../../../shared/models/blocklist'
5import { getSort } from '../utils' 5import { getSort } from '../utils'
6import * as Bluebird from 'bluebird' 6import * as Bluebird from 'bluebird'
7import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/typings/models' 7import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/typings/models'
8import { Op } from 'sequelize'
8 9
9enum ScopeNames { 10enum ScopeNames {
10 WITH_ACCOUNT = 'WITH_ACCOUNT', 11 WITH_ACCOUNT = 'WITH_ACCOUNT',
@@ -75,6 +76,31 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
75 }) 76 })
76 BlockedServer: ServerModel 77 BlockedServer: ServerModel
77 78
79 static isServerMutedByMulti (accountIds: number[], targetServerId: number) {
80 const query = {
81 attributes: [ 'accountId', 'id' ],
82 where: {
83 accountId: {
84 [Op.in]: accountIds // FIXME: sequelize ANY seems broken
85 },
86 targetServerId
87 },
88 raw: true
89 }
90
91 return ServerBlocklistModel.unscoped()
92 .findAll(query)
93 .then(rows => {
94 const result: { [accountId: number]: boolean } = {}
95
96 for (const accountId of accountIds) {
97 result[accountId] = !!rows.find(r => r.accountId === accountId)
98 }
99
100 return result
101 })
102 }
103
78 static loadByAccountAndHost (accountId: number, host: string): Bluebird<MServerBlocklist> { 104 static loadByAccountAndHost (accountId: number, host: string): Bluebird<MServerBlocklist> {
79 const query = { 105 const query = {
80 where: { 106 where: {