diff --git a/desktop/src/features/channels/ui/ChannelScreen.tsx b/desktop/src/features/channels/ui/ChannelScreen.tsx index ac79b84d4..9ef61e234 100644 --- a/desktop/src/features/channels/ui/ChannelScreen.tsx +++ b/desktop/src/features/channels/ui/ChannelScreen.tsx @@ -740,6 +740,7 @@ export function ChannelScreen({ agentConversationMarkers, agentLookupReady, agentPubkeys: routingAgentPubkeys, + currentPubkey, enabled: isChannelTasksEnabled, goChannel, messageProfilesReady, diff --git a/desktop/src/features/channels/ui/useAgentConversationRouteTarget.ts b/desktop/src/features/channels/ui/useAgentConversationRouteTarget.ts index 09f10bbd2..4a66cceb0 100644 --- a/desktop/src/features/channels/ui/useAgentConversationRouteTarget.ts +++ b/desktop/src/features/channels/ui/useAgentConversationRouteTarget.ts @@ -8,6 +8,7 @@ import { collectMessageMentionPubkeys } from "@/features/messages/lib/formatTime import type { TimelineMessage } from "@/features/messages/types"; import type { Channel } from "@/shared/api/types"; import { normalizePubkey } from "@/shared/lib/pubkey"; +import { getDmTaskAgentPubkeys } from "./ChannelPane.helpers"; type GoChannel = ( channelId: string, @@ -24,6 +25,7 @@ type UseAgentConversationRouteTargetInput = { agentConversationMarkers: readonly AgentConversationMarker[]; agentPubkeys: ReadonlySet; agentLookupReady: boolean; + currentPubkey?: string; enabled: boolean; goChannel: GoChannel; messageProfilesReady: boolean; @@ -36,30 +38,12 @@ type UseAgentConversationRouteTargetInput = { timelineMessages: readonly TimelineMessage[]; }; -function getSingleDmAgentPubkey( - channel: Channel, - agentPubkeys: ReadonlySet, -) { - if (channel.channelType !== "dm") { - return ""; - } - - const dmAgentPubkeys = new Map(); - for (const pubkey of channel.participantPubkeys) { - const normalized = normalizePubkey(pubkey); - if (agentPubkeys.has(normalized)) { - dmAgentPubkeys.set(normalized, pubkey); - } - } - - return dmAgentPubkeys.size === 1 ? [...dmAgentPubkeys.values()][0] : ""; -} - export function useAgentConversationRouteTarget({ activeChannel, agentConversationMarkers, agentLookupReady, agentPubkeys, + currentPubkey, enabled, goChannel, messageProfilesReady, @@ -114,7 +98,11 @@ export function useAgentConversationRouteTarget({ collectMessageMentionPubkeys([sourceMessage]).find((pubkey) => agentPubkeys.has(normalizePubkey(pubkey)), ) ?? ""; - const dmAgentPubkey = getSingleDmAgentPubkey(activeChannel, agentPubkeys); + const [dmAgentPubkey = ""] = getDmTaskAgentPubkeys({ + channel: activeChannel, + currentPubkey, + knownAgentPubkeys: agentPubkeys, + }); const taskAgentPubkey = marker?.agentPubkey || (sourceAuthorIsAgent ? (sourceMessage.pubkey ?? "") : "") || @@ -161,6 +149,7 @@ export function useAgentConversationRouteTarget({ agentConversationMarkers, agentLookupReady, agentPubkeys, + currentPubkey, enabled, goChannel, messageProfilesReady,