- static listFollowersForApi (options: {
- actorIds: number[]
- start: number
- count: number
- sort: string
- state?: FollowState
- actorType?: ActivityPubActorType
- search?: string
- }) {
- const { actorIds, start, count, sort, search, state, actorType } = options
-
- const followWhere = state ? { state } : {}
- const followerWhere: WhereOptions = {}
-
- if (search) {
- const escapedSearch = ActorFollowModel.sequelize.escape('%' + search + '%')
-
- Object.assign(followerWhere, {
- id: {
- [Op.in]: literal(
- `(` +
- `SELECT "actor".id FROM actor LEFT JOIN server on server.id = actor."serverId" ` +
- `WHERE "preferredUsername" ILIKE ${escapedSearch} OR "host" ILIKE ${escapedSearch}` +
- `)`
- )
- }
- })
- }
-
- if (actorType) {
- Object.assign(followerWhere, { type: actorType })
- }
-
- const getQuery = (forCount: boolean) => {
- const actorModel = forCount
- ? ActorModel.unscoped()
- : ActorModel
-
- return {
- distinct: true,
-
- offset: start,
- limit: count,
- order: getFollowsSort(sort),
- where: followWhere,
- include: [
- {
- model: actorModel,
- required: true,
- as: 'ActorFollower',
- where: followerWhere
- },
- {
- model: actorModel,
- as: 'ActorFollowing',
- required: true,
- where: {
- id: {
- [Op.in]: actorIds
- }
- }
- }
- ]
- }
- }
-