diff options
| author | Hazel K <acomputerdog@gmail.com> | 2024-10-07 18:56:48 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2024-11-02 17:39:16 -0400 |
| commit | 37fd454f700f6ca844331094210618fd3a1978d2 (patch) | |
| tree | 2080ef1be815bf595f4bf94a72135410fa525d32 /packages/backend/src/server/api/endpoints/federation | |
| parent | update autogen types (diff) | |
| download | sharkey-37fd454f700f6ca844331094210618fd3a1978d2.tar.gz sharkey-37fd454f700f6ca844331094210618fd3a1978d2.tar.bz2 sharkey-37fd454f700f6ca844331094210618fd3a1978d2.zip | |
factor out shared code
Diffstat (limited to 'packages/backend/src/server/api/endpoints/federation')
| -rw-r--r-- | packages/backend/src/server/api/endpoints/federation/followers.ts | 38 | ||||
| -rw-r--r-- | packages/backend/src/server/api/endpoints/federation/following.ts | 38 |
2 files changed, 4 insertions, 72 deletions
diff --git a/packages/backend/src/server/api/endpoints/federation/followers.ts b/packages/backend/src/server/api/endpoints/federation/followers.ts index 7a1056f772..d5b80035df 100644 --- a/packages/backend/src/server/api/endpoints/federation/followers.ts +++ b/packages/backend/src/server/api/endpoints/federation/followers.ts @@ -3,13 +3,9 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { Inject, Injectable } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; -import { MiBlocking, MiUserProfile, MiFollowing, type FollowingsRepository } from '@/models/_.js'; -import { QueryService } from '@/core/QueryService.js'; import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js'; -import { DI } from '@/di-symbols.js'; -import { RoleService } from '@/core/RoleService.js'; export const meta = { tags: ['federation'], @@ -44,40 +40,10 @@ export const paramDef = { @Injectable() export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export constructor( - @Inject(DI.followingsRepository) - private followingsRepository: FollowingsRepository, - private followingEntityService: FollowingEntityService, - private queryService: QueryService, - private roleService: RoleService, ) { super(meta, paramDef, async (ps, me) => { - const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId) - .andWhere('following.followeeHost = :host', { host: ps.host }); - - if (!await this.roleService.isModerator(me)) { - query.setParameter('me', me.id); - - // Make sure that the followee doesn't block us, as their profile is included in the response. - query.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followeeId" AND blocking."blockeeId" = :me'); - query.andWhere('blocking.id IS NULL'); - - // Make sure that the followee hasn't hidden this connection. - query.leftJoin(MiUserProfile, 'followee', 'followee."userId" = following."followeeId"'); - query.leftJoin(MiFollowing, 'me_following_followee', 'me_following_followee."followerId" = :me AND me_following_followee."followeeId" = following."followerId"'); - query.andWhere('(followee."userId" = :me OR followee."followersVisibility" = \'public\' OR (followee."followersVisibility" = \'followers\' AND me_following_followee.id IS NOT NULL))'); - - // Make sure that the follower hasn't hidden this connection. - query.leftJoin(MiUserProfile, 'follower', 'follower."userId" = following."followerId"'); - query.leftJoin(MiFollowing, 'me_following_follower', 'me_following_follower."followerId" = :me AND me_following_follower."followeeId" = following."followerId"'); - query.andWhere('(follower."userId" = :me OR follower."followingVisibility" = \'public\' OR (follower."followingVisibility" = \'followers\' AND me_following_follower.id IS NOT NULL))'); - } - - const followings = await query - .limit(ps.limit) - .getMany(); - - return await this.followingEntityService.packMany(followings, me, { populateFollowee: ps.includeFollowee, populateFollower: ps.includeFollower }); + return this.followingEntityService.getFollowers(me, ps); }); } } diff --git a/packages/backend/src/server/api/endpoints/federation/following.ts b/packages/backend/src/server/api/endpoints/federation/following.ts index bc60ffcb69..215f94fbcc 100644 --- a/packages/backend/src/server/api/endpoints/federation/following.ts +++ b/packages/backend/src/server/api/endpoints/federation/following.ts @@ -3,13 +3,9 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { Inject, Injectable } from '@nestjs/common'; +import { Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; -import { MiBlocking, MiUserProfile, MiFollowing, type FollowingsRepository } from '@/models/_.js'; -import { QueryService } from '@/core/QueryService.js'; import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js'; -import { DI } from '@/di-symbols.js'; -import { RoleService } from '@/core/RoleService.js'; export const meta = { tags: ['federation'], @@ -44,40 +40,10 @@ export const paramDef = { @Injectable() export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export constructor( - @Inject(DI.followingsRepository) - private followingsRepository: FollowingsRepository, - private followingEntityService: FollowingEntityService, - private queryService: QueryService, - private roleService: RoleService, ) { super(meta, paramDef, async (ps, me) => { - const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId) - .andWhere('following.followerHost = :host', { host: ps.host }); - - if (!await this.roleService.isModerator(me)) { - query.setParameter('me', me.id); - - // Make sure that the followee doesn't block us, as their profile is included in the response. - query.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followeeId" AND blocking."blockeeId" = :me'); - query.andWhere('blocking.id IS NULL'); - - // Make sure that the followee hasn't hidden this connection. - query.leftJoin(MiUserProfile, 'followee', 'followee."userId" = following."followeeId"'); - query.leftJoin(MiFollowing, 'me_following_followee', 'me_following_followee."followerId" = :me AND me_following_followee."followeeId" = following."followerId"'); - query.andWhere('(followee."userId" = :me OR followee."followersVisibility" = \'public\' OR (followee."followersVisibility" = \'followers\' AND me_following_followee.id IS NOT NULL))'); - - // Make sure that the follower hasn't hidden this connection. - query.leftJoin(MiUserProfile, 'follower', 'follower."userId" = following."followerId"'); - query.leftJoin(MiFollowing, 'me_following_follower', 'me_following_follower."followerId" = :me AND me_following_follower."followeeId" = following."followerId"'); - query.andWhere('(follower."userId" = :me OR follower."followingVisibility" = \'public\' OR (follower."followingVisibility" = \'followers\' AND me_following_follower.id IS NOT NULL))'); - } - - const followings = await query - .limit(ps.limit) - .getMany(); - - return await this.followingEntityService.packMany(followings, me, { populateFollowee: ps.includeFollowee, populateFollower: ps.includeFollower }); + return this.followingEntityService.getFollowing(me, ps); }); } } |