From 8f0df1f01cf31ad3c520a800d60099581e1641fd Mon Sep 17 00:00:00 2001 From: Hazel K Date: Fri, 4 Oct 2024 20:57:24 -0400 Subject: [PATCH] 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();