From f30c95e51ac9a670c0e3f1fc343fc6d79111fcca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AC=B4=EB=9D=BC=EC=BF=A0=EB=AA=A8?= Date: Sat, 7 Sep 2024 19:21:08 +0900 Subject: [PATCH] fix(reaction): don't include blocked/muted users' reaction to query --- packages/backend/src/core/QueryService.ts | 34 +++++++++++++++++++ .../server/api/endpoints/notes/reactions.ts | 6 ++++ .../server/api/endpoints/users/reactions.ts | 5 +++ 3 files changed, 45 insertions(+) diff --git a/packages/backend/src/core/QueryService.ts b/packages/backend/src/core/QueryService.ts index e4952ecf1..79e5e0f2b 100644 --- a/packages/backend/src/core/QueryService.ts +++ b/packages/backend/src/core/QueryService.ts @@ -119,6 +119,26 @@ export class QueryService { q.setParameters(blockingQuery.getParameters()); } + @bindThis + public generateBlockedUserQueryForReactions(q: SelectQueryBuilder, me: { id: MiUser['id'] }): void { + const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking') + .select('blocking.blockerId') + .where('blocking.blockeeId = :blockeeId', { blockeeId: me.id }); + + q.andWhere(`note.userId NOT IN (${ blockingQuery.getQuery() })`); + q.setParameters(blockingQuery.getParameters()); + } + + @bindThis + public generateBlockingUserQueryForReactions(q: SelectQueryBuilder, me: { id: MiUser['id'] }): void { + const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking') + .select('blocking.blockeeId') + .where('blocking.blockerId = :blockerId', { blockerId: me.id }); + + q.andWhere(`reaction.userId NOT IN (${ blockingQuery.getQuery() })`); + q.setParameters(blockingQuery.getParameters()); + } + @bindThis public generateBlockQueryForUsers(q: SelectQueryBuilder, me: { id: MiUser['id'] }): void { const blockingQuery = this.blockingsRepository.createQueryBuilder('blocking') @@ -213,6 +233,20 @@ export class QueryService { q.setParameters(mutingQuery.getParameters()); } + @bindThis + public generateMutedUserQueryForReactions(q: SelectQueryBuilder, me: { id: MiUser['id'] }, exclude?: { id: MiUser['id'] }): void { + const mutingQuery = this.mutingsRepository.createQueryBuilder('muting') + .select('muting.muteeId') + .where('muting.muterId = :muterId', { muterId: me.id }); + + if (exclude) { + mutingQuery.andWhere('muting.muteeId != :excludeId', { excludeId: exclude.id }); + } + + q.andWhere(`reaction.userId NOT IN (${ mutingQuery.getQuery() })`); + q.setParameters(mutingQuery.getParameters()); + } + @bindThis public generateVisibilityQuery(q: SelectQueryBuilder, me: { id: MiUser['id'] } | null): void { // This code must always be synchronized with the checks in Notes.isVisibleForMe. diff --git a/packages/backend/src/server/api/endpoints/notes/reactions.ts b/packages/backend/src/server/api/endpoints/notes/reactions.ts index 97b12ab7f..132f93908 100644 --- a/packages/backend/src/server/api/endpoints/notes/reactions.ts +++ b/packages/backend/src/server/api/endpoints/notes/reactions.ts @@ -74,6 +74,12 @@ export default class extends Endpoint { // eslint- query.andWhere('reaction.reaction = :type', { type }); } + if (me) { + this.queryService.generateMutedUserQueryForReactions(query, me); + this.queryService.generateBlockingUserQueryForReactions(query, me); + this.queryService.generateBlockedUserQueryForReactions(query, me); + } + const reactions = await query.limit(ps.limit).getMany(); return await this.noteReactionEntityService.packMany(reactions, me); diff --git a/packages/backend/src/server/api/endpoints/users/reactions.ts b/packages/backend/src/server/api/endpoints/users/reactions.ts index 101394172..fd53d151a 100644 --- a/packages/backend/src/server/api/endpoints/users/reactions.ts +++ b/packages/backend/src/server/api/endpoints/users/reactions.ts @@ -104,6 +104,11 @@ export default class extends Endpoint { // eslint- ); this.queryService.generateVisibilityQuery(query, me); + if (me) { + this.queryService.generateMutedUserQuery(query, me); + this.queryService.generateBlockingUserQuery(query, me); + this.queryService.generateBlockedUserQuery(query, me); + } const reactions = await query .limit(ps.limit)