fix(chat): default the read cursor to 0 when counting unread (#10)
CD — Deployment / deploy (push) Successful in 17s

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 <[email protected]>
Reviewed-on: #10
Reviewed-by: Esiah <[email protected]>
Co-authored-by: Gitea Actions <-[email protected]>
This commit was merged in pull request #10.
This commit is contained in:
Gitea Actions
2026-10-17 13:00:48 +00:00
committed by Esiah
co-authored by Esiah
parent 4d725d9a3b
commit f9ff6ee02c
+3 -3
View File
@@ -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`,