From 6bb204eb8075800934743bd435c2f7bb818798f2 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 27 Nov 2025 08:07:39 -0500 Subject: [PATCH] refac --- src/lib/components/channel/Channel.svelte | 4 +++- src/lib/stores/index.ts | 2 ++ src/routes/+layout.svelte | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/components/channel/Channel.svelte b/src/lib/components/channel/Channel.svelte index ff3a511b18..3caf18bcab 100644 --- a/src/lib/components/channel/Channel.svelte +++ b/src/lib/components/channel/Channel.svelte @@ -5,7 +5,7 @@ import { onDestroy, onMount, tick } from 'svelte'; import { goto } from '$app/navigation'; - import { chatId, showSidebar, socket, user } from '$lib/stores'; + import { chatId, channelId as _channelId, showSidebar, socket, user } from '$lib/stores'; import { getChannelById, getChannelMessages, sendMessage } from '$lib/apis/channels'; import Messages from './Messages.svelte'; @@ -62,6 +62,7 @@ currentId = id; updateLastReadAt(id); + _channelId.set(id); top = false; messages = null; @@ -220,6 +221,7 @@ onDestroy(() => { // last read at updateLastReadAt(id); + _channelId.set(null); $socket?.off('events:channel', channelEventHandler); }); diff --git a/src/lib/stores/index.ts b/src/lib/stores/index.ts index c4c2dc10c9..57257d59d3 100644 --- a/src/lib/stores/index.ts +++ b/src/lib/stores/index.ts @@ -51,6 +51,8 @@ export const chatId = writable(''); export const chatTitle = writable(''); export const channels = writable([]); +export const channelId = writable(null); + export const chats = writable(null); export const pinnedChats = writable([]); export const tags = writable([]); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index a42c975a62..a153423909 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -29,7 +29,8 @@ appInfo, toolServers, playingNotificationSound, - channels + channels, + channelId } from '$lib/stores'; import { goto } from '$app/navigation'; import { page } from '$app/stores'; @@ -486,7 +487,7 @@ const data = event?.data?.data ?? null; if ($channels) { - if ($channels.find((ch) => ch.id === event.channel_id)) { + if ($channels.find((ch) => ch.id === event.channel_id) && $channelId !== event.channel_id) { channels.set( $channels.map((ch) => { if (ch.id === event.channel_id) {