aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account-blocklist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account/account-blocklist.ts')
-rw-r--r--server/models/account/account-blocklist.ts24
1 files changed, 20 insertions, 4 deletions
diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts
index 54ac290c4..efd6ed59e 100644
--- a/server/models/account/account-blocklist.ts
+++ b/server/models/account/account-blocklist.ts
@@ -2,6 +2,7 @@ import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, Updated
2import { AccountModel } from './account' 2import { AccountModel } from './account'
3import { getSort } from '../utils' 3import { getSort } from '../utils'
4import { AccountBlock } from '../../../shared/models/blocklist' 4import { AccountBlock } from '../../../shared/models/blocklist'
5import { Op } from 'sequelize'
5 6
6enum ScopeNames { 7enum ScopeNames {
7 WITH_ACCOUNTS = 'WITH_ACCOUNTS' 8 WITH_ACCOUNTS = 'WITH_ACCOUNTS'
@@ -73,18 +74,33 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> {
73 BlockedAccount: AccountModel 74 BlockedAccount: AccountModel
74 75
75 static isAccountMutedBy (accountId: number, targetAccountId: number) { 76 static isAccountMutedBy (accountId: number, targetAccountId: number) {
77 return AccountBlocklistModel.isAccountMutedByMulti([ accountId ], targetAccountId)
78 .then(result => result[accountId])
79 }
80
81 static isAccountMutedByMulti (accountIds: number[], targetAccountId: number) {
76 const query = { 82 const query = {
77 attributes: [ 'id' ], 83 attributes: [ 'accountId', 'id' ],
78 where: { 84 where: {
79 accountId, 85 accountId: {
86 [Op.any]: accountIds
87 },
80 targetAccountId 88 targetAccountId
81 }, 89 },
82 raw: true 90 raw: true
83 } 91 }
84 92
85 return AccountBlocklistModel.unscoped() 93 return AccountBlocklistModel.unscoped()
86 .findOne(query) 94 .findAll(query)
87 .then(a => !!a) 95 .then(rows => {
96 const result: { [accountId: number]: boolean } = {}
97
98 for (const accountId of accountIds) {
99 result[accountId] = !!rows.find(r => r.accountId === accountId)
100 }
101
102 return result
103 })
88 } 104 }
89 105
90 static loadByAccountAndTarget (accountId: number, targetAccountId: number) { 106 static loadByAccountAndTarget (accountId: number, targetAccountId: number) {