From 7842847f6b47ea676ede67f92cd9e147995ee941 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Wed, 13 Aug 2025 11:56:31 -0400 Subject: [PATCH] implement QueryService.generateExcludedRepliesQueryForNotes --- packages/backend/src/core/QueryService.ts | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/backend/src/core/QueryService.ts b/packages/backend/src/core/QueryService.ts index ac608071f4..cb7cfb4453 100644 --- a/packages/backend/src/core/QueryService.ts +++ b/packages/backend/src/core/QueryService.ts @@ -80,6 +80,35 @@ export class QueryService { return q; } + /** + * Exclude replies from the queries, used for timelines. + * withRepliesProp can be specified to additionally allow replies when a given property is true. + * Must match logic NoteVisibilityService.shouldSilenceForFollowWithoutReplies. + */ + @bindThis + public generateExcludedRepliesQueryForNotes(q: SelectQueryBuilder, me?: { id: MiUser['id'] } | null, withRepliesProp?: string): SelectQueryBuilder { + return q + .andWhere(new Brackets(qb => { + if (withRepliesProp) { + // Allow if query specifies it + qb.orWhere(`${withRepliesProp} = true`); + } + + return this + // Allow if we're following w/ replies + .orFollowingUser(qb, ':meId', 'note.userId', true) + // Allow if it's not a reply + .orWhere('note.replyId IS NULL') // 返信ではない + // Allow if it's a self-reply (user replied to themself) + .orWhere('note.replyUserId = note.userId') + // Allow if it's a reply to me + .orWhere('note.replyUserId = :meId') + // Allow if it's my reply + .orWhere('note.userId = :meId'); + })) + .setParameters({ meId: me?.id ?? null }); + } + // ここでいうBlockedは被Blockedの意 @bindThis public generateBlockedUserQueryForNotes(q: SelectQueryBuilder, me: { id: MiUser['id'] }): SelectQueryBuilder {