aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account')
-rw-r--r--server/models/account/account-blocklist.ts38
1 files changed, 38 insertions, 0 deletions
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'
5import { Op } from 'sequelize' 5import { Op } from 'sequelize'
6import * as Bluebird from 'bluebird' 6import * as Bluebird from 'bluebird'
7import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models' 7import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models'
8import { ActorModel } from '../activitypub/actor'
9import { ServerModel } from '../server/server'
8 10
9enum ScopeNames { 11enum ScopeNames {
10 WITH_ACCOUNTS = 'WITH_ACCOUNTS' 12 WITH_ACCOUNTS = 'WITH_ACCOUNTS'
@@ -149,6 +151,42 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> {
149 }) 151 })
150 } 152 }
151 153
154 static listHandlesBlockedBy (accountIds: number[]): Bluebird<string[]> {
155 const query = {
156 attributes: [],
157 where: {
158 accountId: {
159 [Op.in]: accountIds
160 }
161 },
162 include: [
163 {
164 attributes: [ 'id' ],
165 model: AccountModel.unscoped(),
166 required: true,
167 as: 'BlockedAccount',
168 include: [
169 {
170 attributes: [ 'preferredUsername' ],
171 model: ActorModel.unscoped(),
172 required: true,
173 include: [
174 {
175 attributes: [ 'host' ],
176 model: ServerModel.unscoped(),
177 required: true
178 }
179 ]
180 }
181 ]
182 }
183 ]
184 }
185
186 return AccountBlocklistModel.findAll(query)
187 .then(entries => entries.map(e => `${e.BlockedAccount.Actor.preferredUsername}@${e.BlockedAccount.Actor.Server.host}`))
188 }
189
152 toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock { 190 toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock {
153 return { 191 return {
154 byAccount: this.ByAccount.toFormattedJSON(), 192 byAccount: this.ByAccount.toFormattedJSON(),