From c566fa1f3689e6deac2314f04eec1490ef1e4ba7 Mon Sep 17 00:00:00 2001 From: Hazel K Date: Fri, 4 Oct 2024 17:55:02 -0400 Subject: [PATCH 1/8] require auth for followers & following endpoints --- .../backend/src/server/api/endpoints/federation/followers.ts | 3 ++- .../backend/src/server/api/endpoints/federation/following.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/federation/followers.ts b/packages/backend/src/server/api/endpoints/federation/followers.ts index 45a38e86d9..b801935293 100644 --- a/packages/backend/src/server/api/endpoints/federation/followers.ts +++ b/packages/backend/src/server/api/endpoints/federation/followers.ts @@ -13,7 +13,8 @@ import { DI } from '@/di-symbols.js'; export const meta = { tags: ['federation'], - requireCredential: false, + requireCredential: true, + kind: 'read:account', res: { type: 'array', diff --git a/packages/backend/src/server/api/endpoints/federation/following.ts b/packages/backend/src/server/api/endpoints/federation/following.ts index 23257ae926..eb49ae247c 100644 --- a/packages/backend/src/server/api/endpoints/federation/following.ts +++ b/packages/backend/src/server/api/endpoints/federation/following.ts @@ -13,7 +13,8 @@ import { DI } from '@/di-symbols.js'; export const meta = { tags: ['federation'], - requireCredential: false, + requireCredential: true, + kind: 'read:account', res: { type: 'array', From 8f0df1f01cf31ad3c520a800d60099581e1641fd Mon Sep 17 00:00:00 2001 From: Hazel K Date: Fri, 4 Oct 2024 20:57:24 -0400 Subject: [PATCH 2/8] check for blocks in following / followers endpoints --- .../src/server/api/endpoints/federation/followers.ts | 9 ++++++++- .../src/server/api/endpoints/federation/following.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/federation/followers.ts b/packages/backend/src/server/api/endpoints/federation/followers.ts index b801935293..29c5372033 100644 --- a/packages/backend/src/server/api/endpoints/federation/followers.ts +++ b/packages/backend/src/server/api/endpoints/federation/followers.ts @@ -5,10 +5,11 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; -import type { FollowingsRepository } from '@/models/_.js'; +import { MiBlocking, 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'], @@ -48,11 +49,17 @@ export default class extends Endpoint { // eslint- 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.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followerId" AND blocking."blockeeId" = :me', { me: me.id }); + query.andWhere('blocking.id IS NULL'); + } + const followings = await query .limit(ps.limit) .getMany(); diff --git a/packages/backend/src/server/api/endpoints/federation/following.ts b/packages/backend/src/server/api/endpoints/federation/following.ts index eb49ae247c..0b36ffa4e1 100644 --- a/packages/backend/src/server/api/endpoints/federation/following.ts +++ b/packages/backend/src/server/api/endpoints/federation/following.ts @@ -5,10 +5,11 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; -import type { FollowingsRepository } from '@/models/_.js'; +import { MiBlocking, 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'], @@ -48,11 +49,17 @@ export default class extends Endpoint { // eslint- 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.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followeeId" AND blocking."blockeeId" = :me', { me: me.id }); + query.andWhere('blocking.id IS NULL'); + } + const followings = await query .limit(ps.limit) .getMany(); From 65d81a4ae2f7b55517ff5f3c26d0b14751f81998 Mon Sep 17 00:00:00 2001 From: Hazel K Date: Fri, 4 Oct 2024 20:57:30 -0400 Subject: [PATCH 3/8] Revert "fix incorrect populated object in followers endpoint" This reverts commit 7b9473bf4c0b55facede0e1d1e33297d14184110. --- .../backend/src/server/api/endpoints/federation/followers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/federation/followers.ts b/packages/backend/src/server/api/endpoints/federation/followers.ts index 29c5372033..42c0c29fa6 100644 --- a/packages/backend/src/server/api/endpoints/federation/followers.ts +++ b/packages/backend/src/server/api/endpoints/federation/followers.ts @@ -56,7 +56,7 @@ export default class extends Endpoint { // eslint- .andWhere('following.followeeHost = :host', { host: ps.host }); if (!await this.roleService.isModerator(me)) { - query.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followerId" AND blocking."blockeeId" = :me', { me: me.id }); + query.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followeeId" AND blocking."blockeeId" = :me', { me: me.id }); query.andWhere('blocking.id IS NULL'); } From 3a72bf453a6e37a9bbf96892d126c261cb4475dd Mon Sep 17 00:00:00 2001 From: Hazel K Date: Fri, 4 Oct 2024 22:07:30 -0400 Subject: [PATCH 4/8] respect following privacy settings --- .../api/endpoints/federation/followers.ts | 17 +++++++++++++++-- .../api/endpoints/federation/following.ts | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/federation/followers.ts b/packages/backend/src/server/api/endpoints/federation/followers.ts index 42c0c29fa6..7a1056f772 100644 --- a/packages/backend/src/server/api/endpoints/federation/followers.ts +++ b/packages/backend/src/server/api/endpoints/federation/followers.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; -import { MiBlocking, type FollowingsRepository } from '@/models/_.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'; @@ -56,8 +56,21 @@ export default class extends Endpoint { // eslint- .andWhere('following.followeeHost = :host', { host: ps.host }); if (!await this.roleService.isModerator(me)) { - query.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followeeId" AND blocking."blockeeId" = :me', { me: me.id }); + 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 diff --git a/packages/backend/src/server/api/endpoints/federation/following.ts b/packages/backend/src/server/api/endpoints/federation/following.ts index 0b36ffa4e1..bc60ffcb69 100644 --- a/packages/backend/src/server/api/endpoints/federation/following.ts +++ b/packages/backend/src/server/api/endpoints/federation/following.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; -import { MiBlocking, type FollowingsRepository } from '@/models/_.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'; @@ -56,8 +56,21 @@ export default class extends Endpoint { // eslint- .andWhere('following.followerHost = :host', { host: ps.host }); if (!await this.roleService.isModerator(me)) { - query.leftJoin(MiBlocking, 'blocking', 'blocking."blockerId" = following."followeeId" AND blocking."blockeeId" = :me', { me: me.id }); + 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 From 2e6726c81f4f0305e35adb75de50a4057a554382 Mon Sep 17 00:00:00 2001 From: Hazel K Date: Mon, 7 Oct 2024 17:02:29 -0400 Subject: [PATCH 5/8] update autogen types --- packages/misskey-js/src/autogen/apiClientJSDoc.ts | 4 ++-- packages/misskey-js/src/autogen/types.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/misskey-js/src/autogen/apiClientJSDoc.ts b/packages/misskey-js/src/autogen/apiClientJSDoc.ts index fd879d47ec..3fa67b7990 100644 --- a/packages/misskey-js/src/autogen/apiClientJSDoc.ts +++ b/packages/misskey-js/src/autogen/apiClientJSDoc.ts @@ -1890,7 +1890,7 @@ declare module '../api.js' { /** * No description provided. * - * **Credential required**: *No* + * **Credential required**: *Yes* / **Permission**: *read:account* */ request( endpoint: E, @@ -1901,7 +1901,7 @@ declare module '../api.js' { /** * No description provided. * - * **Credential required**: *No* + * **Credential required**: *Yes* / **Permission**: *read:account* */ request( endpoint: E, diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index 2265805352..e275e4b475 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -1645,7 +1645,7 @@ export type paths = { * federation/followers * @description No description provided. * - * **Credential required**: *No* + * **Credential required**: *Yes* / **Permission**: *read:account* */ post: operations['federation___followers']; }; @@ -1654,7 +1654,7 @@ export type paths = { * federation/following * @description No description provided. * - * **Credential required**: *No* + * **Credential required**: *Yes* / **Permission**: *read:account* */ post: operations['federation___following']; }; @@ -15563,7 +15563,7 @@ export type operations = { * federation/followers * @description No description provided. * - * **Credential required**: *No* + * **Credential required**: *Yes* / **Permission**: *read:account* */ federation___followers: { requestBody: { @@ -15626,7 +15626,7 @@ export type operations = { * federation/following * @description No description provided. * - * **Credential required**: *No* + * **Credential required**: *Yes* / **Permission**: *read:account* */ federation___following: { requestBody: { From 37fd454f700f6ca844331094210618fd3a1978d2 Mon Sep 17 00:00:00 2001 From: Hazel K Date: Mon, 7 Oct 2024 18:56:48 -0400 Subject: [PATCH 6/8] factor out shared code --- .../core/entities/FollowingEntityService.ts | 68 ++++++++++++++++++- .../api/endpoints/federation/followers.ts | 38 +---------- .../api/endpoints/federation/following.ts | 38 +---------- 3 files changed, 69 insertions(+), 75 deletions(-) diff --git a/packages/backend/src/core/entities/FollowingEntityService.ts b/packages/backend/src/core/entities/FollowingEntityService.ts index d2dbaf2270..c09b24f809 100644 --- a/packages/backend/src/core/entities/FollowingEntityService.ts +++ b/packages/backend/src/core/entities/FollowingEntityService.ts @@ -8,12 +8,15 @@ import { DI } from '@/di-symbols.js'; import type { FollowingsRepository } from '@/models/_.js'; import { awaitAll } from '@/misc/prelude/await-all.js'; import type { Packed } from '@/misc/json-schema.js'; -import type { } from '@/models/Blocking.js'; -import type { MiUser } from '@/models/User.js'; -import type { MiFollowing } from '@/models/Following.js'; +import { MiBlocking } from '@/models/Blocking.js'; +import { MiUserProfile } from '@/models/UserProfile.js'; +import type { MiLocalUser, MiUser } from '@/models/User.js'; +import { MiFollowing } from '@/models/Following.js'; import { bindThis } from '@/decorators.js'; import { IdService } from '@/core/IdService.js'; import { UserEntityService } from './UserEntityService.js'; +import { QueryService } from '@/core/QueryService.js'; +import { RoleService } from '@/core/RoleService.js'; type LocalFollowerFollowing = MiFollowing & { followerHost: null; @@ -47,6 +50,8 @@ export class FollowingEntityService { private userEntityService: UserEntityService, private idService: IdService, + private queryService: QueryService, + private roleService: RoleService, ) { } @@ -70,6 +75,53 @@ export class FollowingEntityService { return following.followeeHost != null; } + @bindThis + public async getFollowing(me: MiLocalUser, params: FollowsQueryParams) { + return await this.getFollows(me, params, 'following.followerHost = :host'); + } + + @bindThis + public async getFollowers(me: MiLocalUser, params: FollowsQueryParams) { + return await this.getFollows(me, params, 'following.followeeHost = :host'); + } + + private async getFollows(me: MiLocalUser, params: FollowsQueryParams, condition: string) { + const builder = this.followingsRepository.createQueryBuilder('following'); + const query = this.queryService + .makePaginationQuery(builder, params.sinceId, params.untilId) + .andWhere(condition, { host: params.host }) + .limit(params.limit); + + if (!await this.roleService.isModerator(me)) { + query.setParameter('me', me.id); + + // Make sure that the followee doesn't block us, if their profile will be included. + if (params.includeFollowee) { + query.leftJoin(MiBlocking, 'followee_blocking', 'followee_blocking."blockerId" = following."followeeId" AND followee_blocking."blockeeId" = :me'); + query.andWhere('followee_blocking.id IS NULL'); + } + + // Make sure that the follower doesn't block us, if their profile will be included. + if (params.includeFollower) { + query.leftJoin(MiBlocking, 'follower_blocking', 'follower_blocking."blockerId" = following."followerId" AND follower_blocking."blockeeId" = :me'); + query.andWhere('follower_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.getMany(); + return await this.packMany(followings, me, { populateFollowee: params.includeFollowee, populateFollower: params.includeFollower }); + } + @bindThis public async pack( src: MiFollowing['id'] | MiFollowing, @@ -124,3 +176,13 @@ export class FollowingEntityService { } } + +interface FollowsQueryParams { + readonly host: string; + readonly limit: number; + readonly includeFollower: boolean; + readonly includeFollowee: boolean; + + readonly sinceId?: string; + readonly untilId?: string; +} 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 { // 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 { // 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); }); } } From 872f987845bfae3909973882a8f20e3f7809ea89 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sat, 2 Nov 2024 12:03:14 -0400 Subject: [PATCH 7/8] hide instance following / followers tabs from logged-out users --- packages/frontend/src/pages/instance-info.vue | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/frontend/src/pages/instance-info.vue b/packages/frontend/src/pages/instance-info.vue index bc3e93ad7d..a5e6e5ac33 100644 --- a/packages/frontend/src/pages/instance-info.vue +++ b/packages/frontend/src/pages/instance-info.vue @@ -194,6 +194,7 @@ import { getProxiedImageUrlNullable } from '@/scripts/media-proxy.js'; import { dateString } from '@/filters/date.js'; import MkTextarea from '@/components/MkTextarea.vue'; import MkInfo from '@/components/MkInfo.vue'; +import { $i } from '@/account.js'; const props = defineProps<{ host: string; @@ -422,20 +423,28 @@ const headerTabs = computed(() => [{ key: 'users', title: i18n.ts.users, icon: 'ti ti-users', -}, { - key: 'following', - title: i18n.ts.following, - icon: 'ti ti-arrow-right', -}, { - key: 'followers', - title: i18n.ts.followers, - icon: 'ti ti-arrow-left', -}, { +}, ...getFollowingTabs(), { key: 'raw', title: 'Raw', icon: 'ti ti-code', }]); +function getFollowingTabs() { + if (!$i) return []; + return [ + { + key: 'following', + title: i18n.ts.following, + icon: 'ti ti-arrow-right', + }, + { + key: 'followers', + title: i18n.ts.followers, + icon: 'ti ti-arrow-left', + }, + ]; +} + definePageMetadata(() => ({ title: props.host, icon: 'ti ti-server', From ddf572c22fcc06f5f9a913d327aa993c282fb37b Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sat, 2 Nov 2024 17:43:11 -0400 Subject: [PATCH 8/8] fix lint errors in FollowingEntityService.ts --- packages/backend/src/core/entities/FollowingEntityService.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/backend/src/core/entities/FollowingEntityService.ts b/packages/backend/src/core/entities/FollowingEntityService.ts index c09b24f809..d54c954bf2 100644 --- a/packages/backend/src/core/entities/FollowingEntityService.ts +++ b/packages/backend/src/core/entities/FollowingEntityService.ts @@ -14,9 +14,9 @@ import type { MiLocalUser, MiUser } from '@/models/User.js'; import { MiFollowing } from '@/models/Following.js'; import { bindThis } from '@/decorators.js'; import { IdService } from '@/core/IdService.js'; -import { UserEntityService } from './UserEntityService.js'; import { QueryService } from '@/core/QueryService.js'; import { RoleService } from '@/core/RoleService.js'; +import { UserEntityService } from './UserEntityService.js'; type LocalFollowerFollowing = MiFollowing & { followerHost: null; @@ -176,7 +176,6 @@ export class FollowingEntityService { } } - interface FollowsQueryParams { readonly host: string; readonly limit: number;