diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account-blocklist.ts | 38 | ||||
-rw-r--r-- | server/models/server/server-blocklist.ts | 21 |
2 files changed, 59 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' | |||
5 | import { Op } from 'sequelize' | 5 | import { Op } from 'sequelize' |
6 | import * as Bluebird from 'bluebird' | 6 | import * as Bluebird from 'bluebird' |
7 | import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models' | 7 | import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models' |
8 | import { ActorModel } from '../activitypub/actor' | ||
9 | import { ServerModel } from '../server/server' | ||
8 | 10 | ||
9 | enum ScopeNames { | 11 | enum 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(), |
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<ServerBlocklistModel> { | |||
120 | return ServerBlocklistModel.findOne(query) | 120 | return ServerBlocklistModel.findOne(query) |
121 | } | 121 | } |
122 | 122 | ||
123 | static listHostsBlockedBy (accountIds: number[]): Bluebird<string[]> { | ||
124 | const query = { | ||
125 | attributes: [ ], | ||
126 | where: { | ||
127 | accountId: { | ||
128 | [Op.in]: accountIds | ||
129 | } | ||
130 | }, | ||
131 | include: [ | ||
132 | { | ||
133 | attributes: [ 'host' ], | ||
134 | model: ServerModel.unscoped(), | ||
135 | required: true | ||
136 | } | ||
137 | ] | ||
138 | } | ||
139 | |||
140 | return ServerBlocklistModel.findAll(query) | ||
141 | .then(entries => entries.map(e => e.BlockedServer.host)) | ||
142 | } | ||
143 | |||
123 | static listForApi (parameters: { | 144 | static listForApi (parameters: { |
124 | start: number | 145 | start: number |
125 | count: number | 146 | count: number |