From 97a396235225afc445256c05c7ea4792a3192826 Mon Sep 17 00:00:00 2001 From: klopez4212 Date: Mon, 29 Jun 2026 19:16:08 +0100 Subject: [PATCH] Seed task link context into channel cache --- desktop/src/app/routes/ChannelRouteScreen.tsx | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/desktop/src/app/routes/ChannelRouteScreen.tsx b/desktop/src/app/routes/ChannelRouteScreen.tsx index 5c9421c2c..4141c6984 100644 --- a/desktop/src/app/routes/ChannelRouteScreen.tsx +++ b/desktop/src/app/routes/ChannelRouteScreen.tsx @@ -1,4 +1,5 @@ import * as React from "react"; +import { useQueryClient } from "@tanstack/react-query"; import { getCachedSearchHitEvent } from "@/app/navigation/searchHitEventCache"; import { useAppNavigation } from "@/app/navigation/useAppNavigation"; @@ -8,6 +9,8 @@ import { getThreadReference, isBroadcastReply, } from "@/features/messages/lib/threading"; +import { mergeTimelineCacheMessages } from "@/features/messages/hooks"; +import { channelMessagesKey } from "@/features/messages/lib/messageQueryKeys"; import { useProfileQuery } from "@/features/profile/hooks"; import { relayClient } from "@/shared/api/relayClient"; import { useIdentityQuery } from "@/shared/api/hooks"; @@ -128,6 +131,16 @@ async function fetchRouteTargetEvents( return [...eventsById.values()]; } +function mergeRouteEvents( + currentEvents: RelayEvent[] | undefined, + routeEvents: RelayEvent[], +): RelayEvent[] { + return routeEvents.reduce( + (messages, event) => mergeTimelineCacheMessages(messages, event), + currentEvents ?? [], + ); +} + export function ChannelRouteScreen({ channelId, selectedPostId, @@ -136,6 +149,7 @@ export function ChannelRouteScreen({ targetReplyId, targetThreadRootId, }: ChannelRouteScreenProps) { + const queryClient = useQueryClient(); const { closeForumPost, goForumPost } = useAppNavigation(); const channelsQuery = useChannelsQuery(); const identityQuery = useIdentityQuery(); @@ -189,6 +203,10 @@ export function ChannelRouteScreen({ const cachedTarget = getCachedSearchHitEvent(targetMessageId); if (cachedTarget) { + queryClient.setQueryData( + channelMessagesKey(channelId), + (currentEvents) => mergeRouteEvents(currentEvents, [cachedTarget]), + ); setTargetMessageEvents((currentEvents) => currentEvents.some((event) => event.id === cachedTarget.id) ? currentEvents @@ -212,6 +230,10 @@ export function ChannelRouteScreen({ targetThreadRootId, ).then((events) => { if (!isCancelled) { + queryClient.setQueryData( + channelMessagesKey(channelId), + (currentEvents) => mergeRouteEvents(currentEvents, events), + ); setTargetMessageEvents((currentEvents) => { const eventsById = new Map(); for (const event of [...currentEvents, ...events]) { @@ -228,6 +250,7 @@ export function ChannelRouteScreen({ }, [ selectedPostId, channelId, + queryClient, targetAgentConversationReplyId, targetMessageId, targetThreadRootId,