+ static listForApi (parameters: {
+ start: number
+ count: number
+ sort: string
+ search?: string
+ accountId: number
+ }) {
+ const { start, count, sort, search, accountId } = parameters
+
+ const getQuery = (forCount: boolean) => {
+ const query: FindOptions = {
+ offset: start,
+ limit: count,
+ order: getSort(sort),
+ where: { accountId }
+ }
+
+ if (search) {
+ Object.assign(query.where, {
+ [Op.or]: [
+ searchAttribute(search, '$BlockedAccount.name$'),
+ searchAttribute(search, '$BlockedAccount.Actor.url$')
+ ]
+ })
+ }
+
+ if (forCount !== true) {
+ query.include = [
+ {
+ model: AccountModel,
+ required: true,
+ as: 'ByAccount'
+ },
+ {
+ model: AccountModel,
+ required: true,
+ as: 'BlockedAccount'
+ }
+ ]
+ } else if (search) { // We need some joins when counting with search
+ query.include = [
+ {
+ model: AccountModel.unscoped(),
+ required: true,
+ as: 'BlockedAccount',
+ include: [
+ {
+ model: ActorModel.unscoped(),
+ required: true
+ }
+ ]
+ }
+ ]
+ }
+
+ return query
+ }
+
+ return Promise.all([
+ AccountBlocklistModel.count(getQuery(true)),
+ AccountBlocklistModel.findAll(getQuery(false))
+ ]).then(([ total, data ]) => ({ total, data }))
+ }
+
+ static listHandlesBlockedBy (accountIds: number[]): Promise<string[]> {