mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
fix(desktop): refresh DM sidebar in real-time when new messages arrive (#183)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user