From efaa8ead96f572e32bee66064a443f13fff7c7dd Mon Sep 17 00:00:00 2001 From: Wes Date: Wed, 25 Mar 2026 14:38:09 -0700 Subject: [PATCH] fix(desktop): refresh DM sidebar in real-time when new messages arrive (#183) Co-authored-by: Claude Opus 4.6 --- .../features/channels/useUnreadChannels.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/desktop/src/features/channels/useUnreadChannels.ts b/desktop/src/features/channels/useUnreadChannels.ts index e08f6ffa4..5d4bc0ac1 100644 --- a/desktop/src/features/channels/useUnreadChannels.ts +++ b/desktop/src/features/channels/useUnreadChannels.ts @@ -1,7 +1,10 @@ import * as React from "react"; import { useQueryClient } from "@tanstack/react-query"; -import { updateChannelLastMessageAt } from "@/features/channels/hooks"; +import { + channelsQueryKey, + updateChannelLastMessageAt, +} from "@/features/channels/hooks"; import { getChannelIdFromTags } from "@/features/messages/lib/threading"; import { mergeTimelineCacheMessages } from "@/features/messages/hooks"; import { relayClient } from "@/shared/api/relayClient"; @@ -180,11 +183,12 @@ export function useUnreadChannels( const handleIncomingMessage = React.useEffectEvent((event: RelayEvent) => { const channelId = getChannelIdFromTags(event.tags); - if ( - !channelId || - channelId === activeChannelId || - !liveChannelIds.has(channelId) - ) { + if (!channelId || channelId === activeChannelId) { + return; + } + + if (!liveChannelIds.has(channelId)) { + void queryClient.invalidateQueries({ queryKey: channelsQueryKey }); return; } @@ -203,6 +207,12 @@ export function useUnreadChannels( ); }); + React.useEffect(() => { + return relayClient.subscribeToReconnects(() => { + void queryClient.invalidateQueries({ queryKey: channelsQueryKey }); + }); + }, [queryClient]); + React.useEffect(() => { if (liveChannelIds.size === 0) { return;