From 2414dfca708f3822f5b1853dd8213146bb89ebf3 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 29 Jun 2026 09:32:00 +0200 Subject: [PATCH] fix: mark in-place created chats as read on new chat (#25782) A chat created in place (new chat -> first message) keeps chatIdProp undefined because the URL is swapped via history.replaceState without a remount, so none of the chatIdProp-gated updateLastReadAt paths fire and the chat is never persisted with a last_read_at. Starting another new chat via initNewChat reset $chatId without marking the outgoing chat read, so on refresh updated_at > last_read_at (NULL) and the chat shows as unread in the sidebar. Mark the outgoing chat read in initNewChat, mirroring navigateHandler. Fixes #25108 Co-authored-by: Claude Opus 4.8 (1M context) --- src/lib/components/chat/Chat.svelte | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 4995c67e61..5729ea1b53 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1199,6 +1199,13 @@ const initNewChat = async () => { console.log('initNewChat'); + + // Mark the outgoing chat as read before resetting; in-place created chats + // keep chatIdProp undefined, so navigateHandler never marks them read. + if ($chatId && !$temporaryChatEnabled) { + updateLastReadAt($chatId); + } + if ($user?.role !== 'admin' && $user?.permissions?.chat?.temporary_enforced) { await temporaryChatEnabled.set(true); }