From f26566e8440ccd3c18706fec1062a2d7be958f56 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Wed, 13 Aug 2025 11:56:14 -0400 Subject: [PATCH] add withReplies option to QueryService.addFollowingUser, .andFollowingUser, and .orFollowingUser --- packages/backend/src/core/QueryService.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/QueryService.ts b/packages/backend/src/core/QueryService.ts index 12efe18f3c..ac608071f4 100644 --- a/packages/backend/src/core/QueryService.ts +++ b/packages/backend/src/core/QueryService.ts @@ -449,27 +449,33 @@ export class QueryService { /** * Adds OR condition that followerProp (user ID) is following followeeProp (user ID). * Both props should be expressions, not raw values. + * If withReplies is set to a boolean, then this method will only count followings with the matching withReplies value. */ @bindThis - public orFollowingUser(q: Q, followerProp: string, followeeProp: string): Q { - return this.addFollowingUser(q, followerProp, followeeProp, 'orWhere'); + public orFollowingUser(q: Q, followerProp: string, followeeProp: string, withReplies?: boolean): Q { + return this.addFollowingUser(q, followerProp, followeeProp, 'orWhere', withReplies); } /** * Adds AND condition that followerProp (user ID) is following followeeProp (user ID). * Both props should be expressions, not raw values. + * If withReplies is set to a boolean, then this method will only count followings with the matching withReplies value. */ @bindThis - public andFollowingUser(q: Q, followerProp: string, followeeProp: string): Q { - return this.addFollowingUser(q, followerProp, followeeProp, 'andWhere'); + public andFollowingUser(q: Q, followerProp: string, followeeProp: string, withReplies?: boolean): Q { + return this.addFollowingUser(q, followerProp, followeeProp, 'andWhere', withReplies); } - private addFollowingUser(q: Q, followerProp: string, followeeProp: string, join: 'andWhere' | 'orWhere'): Q { + private addFollowingUser(q: Q, followerProp: string, followeeProp: string, join: 'andWhere' | 'orWhere', withReplies?: boolean): Q { const followingQuery = this.followingsRepository.createQueryBuilder('following') .select('1') .andWhere(`following.followerId = ${followerProp}`) .andWhere(`following.followeeId = ${followeeProp}`); + if (withReplies !== undefined) { + followingQuery.andWhere('following.withReplies = :withReplies', { withReplies }); + } + return q[join](`EXISTS (${followingQuery.getQuery()})`, followingQuery.getParameters()); };