From 4206764881663b07f7457511c19adf126ac3ab0c Mon Sep 17 00:00:00 2001 From: Anurag Shivarathri Date: Tue, 20 Dec 2022 15:14:00 +0530 Subject: [PATCH] Fix (#6887) --- app/queries/servers/thread.ts | 37 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/app/queries/servers/thread.ts b/app/queries/servers/thread.ts index 4ee78d7dbd..4a200ad8ef 100644 --- a/app/queries/servers/thread.ts +++ b/app/queries/servers/thread.ts @@ -141,7 +141,10 @@ export const prepareThreadsFromReceivedPosts = async (operator: ServerDataOperat }; export const queryThreadsInTeam = (database: Database, teamId: string, onlyUnreads?: boolean, hasReplies?: boolean, isFollowing?: boolean, sort?: boolean, earliest?: number): Query => { - const query: Q.Clause[] = []; + const query: Q.Clause[] = [ + Q.experimentalNestedJoin(POST, CHANNEL), + Q.on(POST, Q.on(CHANNEL, Q.where('delete_at', 0))), + ]; if (isFollowing) { query.push(Q.where('is_following', true)); @@ -189,30 +192,34 @@ export const queryThreads = (database: Database, teamId?: string, onlyUnreads = Q.where('reply_count', Q.gt(0)), ]; + // Only get threads from available channel + const channelCondition: Q.Condition[] = [ + Q.where('delete_at', 0), + ]; + // If teamId is specified, only get threads in that team if (teamId) { - let condition: Q.Condition = Q.where('team_id', teamId); - if (includeDmGm) { - condition = Q.or( - Q.where('team_id', teamId), - Q.where('team_id', ''), + channelCondition.push( + Q.or( + Q.where('team_id', teamId), + Q.where('team_id', ''), + ), ); + } else { + channelCondition.push(Q.where('team_id', teamId)); } - - query.push( - Q.experimentalNestedJoin(POST, CHANNEL), - Q.on(POST, Q.on(CHANNEL, condition)), - ); } else if (!includeDmGm) { // fetching all threads from all teams // excluding DM/GM channels - query.push( - Q.experimentalNestedJoin(POST, CHANNEL), - Q.on(POST, Q.on(CHANNEL, Q.where('team_id', Q.notEq('')))), - ); + channelCondition.push(Q.where('team_id', Q.notEq(''))); } + query.push( + Q.experimentalNestedJoin(POST, CHANNEL), + Q.on(POST, Q.on(CHANNEL, Q.and(...channelCondition))), + ); + if (onlyUnreads) { query.push(Q.where('unread_replies', Q.gt(0))); }