fix(chat): default the read cursor to 0 when counting unread
PR — Ouverture automatique / create-pr (push) Successful in 2s
PR — Ouverture automatique / create-pr (push) Successful in 2s
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.
This commit is contained in:
@@ -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`,
|
||||
|
||||
Reference in New Issue
Block a user