Preserve persistent agent audience order (#1989)

Signed-off-by: npub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsex <6e967af659416160ab4f2fd56d74c8c6f273791ee7bfc9468a1be37c387947be@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1d6t84ajeg9skp2609l2k6axgcme8x7g7u7luj352r03hcwreg7lqnxcsex <6e967af659416160ab4f2fd56d74c8c6f273791ee7bfc9468a1be37c387947be@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
morgmart
2026-07-16 16:18:07 -07:00
committed by GitHub
parent 9b6497402f
commit fb8e6827c7
17 changed files with 531 additions and 128 deletions

View File

@@ -1,6 +1,10 @@
import * as React from "react";
import { ArrowDown } from "lucide-react";
import { useKnownAgentPubkeys } from "@/features/agents/useKnownAgentPubkeys";
import { orderMentionPubkeysByText } from "@/features/messages/lib/orderMentionPubkeys";
import { normalizePubkey } from "@/shared/lib/pubkey";
import { resolveMentionProps } from "@/shared/lib/resolveMentionNames";
import {
buildThreadSummaryFromVisibleEntries,
hasNestedThreadBranches,
@@ -596,6 +600,30 @@ export function MessageThreadPanel({
targetMessageId: scrollTargetId,
});
const knownAgentPubkeys = useKnownAgentPubkeys();
const initialAgentPubkeys = React.useMemo(() => {
if (
!threadHead ||
!currentPubkey ||
normalizePubkey(threadHead.signerPubkey ?? threadHead.pubkey ?? "") !==
normalizePubkey(currentPubkey)
) {
return [];
}
const { mentionPubkeysByName } = resolveMentionProps(
threadHead.tags,
profiles,
);
if (!mentionPubkeysByName) return [];
return orderMentionPubkeysByText(
threadHead.body,
mentionPubkeysByName,
(pubkey) =>
knownAgentPubkeys.has(pubkey) || profiles?.[pubkey]?.isAgent === true,
);
}, [currentPubkey, knownAgentPubkeys, profiles, threadHead]);
if (!threadHead) {
return null;
}
@@ -884,6 +912,7 @@ export function MessageThreadPanel({
audienceContext={{
type: "thread",
threadRootId: threadHead.id,
initialAgentPubkeys,
}}
channelId={channelId}
channelName={channelName}