From f9ff6ee02c7476d83ee0c43095cc5a70dafe7a5b Mon Sep 17 00:00:00 2001 From: Gitea Actions <-2+gitea-actions@noreply.localhost> Date: Sat, 17 Oct 2026 13:00:48 +0000 Subject: [PATCH] fix(chat): default the read cursor to 0 when counting unread (#10) The unread count compared message ids against COALESCE over a scalar subquery with no fallback. When a user had never opened a discussion there was no chat_reads row, so the subquery returned NULL and `m.id > NULL` was never true: the folder never got a badge even though messages from others were unread. Give COALESCE an explicit 0 default so discussions that were never opened count all of the others' messages as unread. --------- Co-authored-by: xEsiah Reviewed-on: https://git.cohaise.dev/Esiah/CoHaiSe-CLOUD/pulls/10 Reviewed-by: Esiah Co-authored-by: Gitea Actions <-2+gitea-actions@noreply.localhost> --- backend/src/routes/chat.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/routes/chat.ts b/backend/src/routes/chat.ts index 04adf61..aaa3b3c 100644 --- a/backend/src/routes/chat.ts +++ b/backend/src/routes/chat.ts @@ -111,9 +111,9 @@ export const registerChatRoutes = (app: App, db: Db, config: Config): void => { AND m.user_id <> ? WHERE f.deleted_at IS NULL AND m.id > COALESCE ( - SELECT cr.last_read_message_id - FROM chat_reads cr - WHERE cr.folder_id = f.id AND cr.user_id = ? ) + ( SELECT cr.last_read_message_id + FROM chat_reads cr + WHERE cr.folder_id = f.id AND cr.user_id = ? ), 0 ) AND ${READ_SQL} GROUP BY f.id HAVING unread > 0`,