diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index feae8b6c0a..7ced4b2c4f 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -1644,7 +1644,16 @@ }); }; $: syncChatRoom($socket, $chatId, $temporaryChatEnabled); - $: if (side && $chatId) openSideChatIds.update((ids) => new Set([...ids, $chatId])); + let openSideChatId: string = ''; + $: if (embedded && $chatId !== openSideChatId) { + openSideChatIds.update((ids) => { + const next = new Set(ids); + next.delete(openSideChatId); + if ($chatId) next.add($chatId); + return next; + }); + openSideChatId = $chatId; + } const chatEventHandler = async (event, cb) => { if (isTemporaryChatId(event.chat_id) && event.chat_id !== $chatId) return; @@ -2222,7 +2231,7 @@ if (joinedChatId && $socket?.connected) $socket.emit('events:chat', { chat_id: joinedChatId, data: { type: 'leave' } }); joinedChatId = ''; - if (side && $chatId) { + if (embedded && $chatId) { if ($temporaryChatEnabled) stopTasksByChatId(localStorage.token, $chatId).catch(console.error); openSideChatIds.update((ids) => {