Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(channels): dedupe reply input nodes (#6401)

Seamus6b6b079feef1
diff --git a/apps/web/src/features/channel/Thread/utils/message-actions.ts b/apps/web/src/features/channel/Thread/utils/message-actions.ts
index e2b174f574..aa5ca6f675 100644
--- a/apps/web/src/features/channel/Thread/utils/message-actions.ts
+++ b/apps/web/src/features/channel/Thread/utils/message-actions.ts
@@ -2,6 +2,7 @@ import { getChannelParams } from '@channel/Channel/link';
import { buildSimpleEntityUrl } from '@core/util/url';
import {
buildReplyTargetMarkdown,
+ isReplyTargetData,
markdownToPlainText,
stripLeadingReplyTargetMarkdown,
} from '@macro-inc/lexical-core';
@@ -72,6 +73,22 @@ export function buildReplyTargetValue(input: {
}): string {
if (!input.message.thread_id) return input.existingValue ?? '';
+ for (const match of (input.existingValue ?? '').matchAll(
+ /<m-reply-target>(.*?)<\/m-reply-target>/gs
+ )) {
+ try {
+ const target: unknown = JSON.parse(match[1]);
+ if (
+ isReplyTargetData(target) &&
+ target.targetMessageId === input.message.id
+ ) {
+ return input.existingValue ?? '';
+ }
+ } catch {
+ // Malformed references should not prevent adding a valid reply target.
+ }
+ }
+
const messageText = markdownToPlainText(
stripMagicChipMarkdown(
stripLeadingReplyTargetMarkdown(input.message.content)
diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.md
index 9b9c8957ce..60797b32da 100644
--- a/docs/AGENT_GUIDE/channels.md
+++ b/docs/AGENT_GUIDE/channels.md
@@ -52,6 +52,8 @@ Hover a message for its action menu. `Reply` on a top-level message opens that t
an existing thread reply, it inserts a one-line reply-target reference into the composer;
clicking the reference navigates back to that reply. If text in the message is
browser-selected before `Reply` is clicked, the reference previews only the selected text.
+Clicking `Reply` again for a message already referenced anywhere in the draft keeps
+the existing reference and draft unchanged, even if a different text selection is used.
For agent-session messages, the reference previews the resolved answer or current activity
rather than the internal Magic Chip marker.
Agent-session announcements use the same ReplyTarget reference for the prompting channel