- static listFollowingForApi (options: {
- id: number
- start: number
- count: number
- sort: string
- state?: FollowState
- actorType?: ActivityPubActorType
- search?: string
- }) {
- const { id, start, count, sort, search, state, actorType } = options
-
- const followWhere = state ? { state } : {}
- const followingWhere: WhereOptions = {}
-
- if (search) {
- Object.assign(followWhere, {
- [Op.or]: [
- searchAttribute(options.search, '$ActorFollowing.preferredUsername$'),
- searchAttribute(options.search, '$ActorFollowing.Server.host$')
- ]
- })
- }
-
- if (actorType) {
- Object.assign(followingWhere, { type: actorType })
- }
-
- const query = {
- distinct: true,
- offset: start,
- limit: count,
- order: getFollowsSort(sort),
- where: followWhere,
- include: [
- {
- model: ActorModel,
- required: true,
- as: 'ActorFollower',
- where: {
- id
- }
- },
- {
- model: ActorModel,
- as: 'ActorFollowing',
- required: true,
- where: followingWhere,
- include: [
- {
- model: ServerModel,
- required: true
- }
- ]
- }
- ]
- }
-
- return ActorFollowModel.findAndCountAll<MActorFollowActorsDefault>(query)
- .then(({ rows, count }) => {
- return {
- data: rows,
- total: count
- }
- })
+ static listInstanceFollowingForApi (options: ListFollowingOptions) {
+ return Promise.all([
+ new InstanceListFollowingQueryBuilder(this.sequelize, options).countFollowing(),
+ new InstanceListFollowingQueryBuilder(this.sequelize, options).listFollowing()
+ ]).then(([ total, data ]) => ({ total, data }))