Skip to content

Commit dce967e

Browse files
loganjLarryBad Janet
authored andcommitted
fix(desktop): bind duplicate mention selections to exact recipients (block#7133)
## Summary Selecting two people or agents named Scout could replace the first recipient with the second even though the message still looked right. This binds each selection to its exact identity: the first keeps `@Scout`, and a conflicting selection gets `@Scout (<full public key>)`. Removing one no longer removes or redirects the other. - Reuse the existing **@ suggestion list**; team selection and automatic agent addressing reserve and reuse distinct labels too. Typing an ambiguous name manually shows an instruction to use the picker and preserves the draft without publishing—in chat, edits and standalone forums. - Share literal mention matching across recipient extraction, removal, display and editing so a shorter name cannot claim another recipient's longer or qualified label. - Rebuild authored references when a message is edited, and use the latest authorized snapshot when reopening or forwarding. Rendering/editing can recover qualified identities only from the message's recorded references, not from a key typed into its body. Unresolvable historical names remain literal rather than guessed recipients. - Wrap full-key labels within narrow/zoomed layouts while keeping their complete accessible label and ordinary mention icons. Edit activation waits for the action menu's focus cleanup before focusing the editor. ### Related issue Targets `main`; mention spacing (block#7128) is already merged. Split from block#7114. This is independent of the block#7124 → block#7125 remote-invitation stack and does not expand agent eligibility or invitation permissions. The separate Enter-selection suffix issue remains tracked in block#7253. ### Testing The desktop unit suite and focused mock-Chromium checks passed on the published integration candidate, including pending-paste selection, edit/forwarding, copy and narrow-layout cases; formatting, types and frontend builds passed. On `0b3b18c0`, 64 focused trust/paste/selection unit tests and six mock-Chromium tests passed with zero browser retries, including actual timeline chip copy → fresh channel paste → send and mismatched-key rejection; TypeScript, changed-file Biome and an isolated E2E build passed. The broader browser run had copy failures before the focused repairs and is not claimed as wholly green. See [live CI](https://github.com/block/buzz/pull/7133/checks) for current-head results. No full local `just ci` pass, native/live-relay or cross-browser validation is claimed. To try it: select two same-name recipients, remove one, send, then edit/reopen and forward; only the intended identities should remain. Type an ambiguous name without choosing a suggestion and check that sending retains the draft with an error. Inspect full-key labels in a narrow window at 150% text size, and open Edit and type immediately. ![Ambiguous mention keeps the chat draft](https://raw.githubusercontent.com/block/buzz/c48053209b36b3b1bf7197cf2d606d27b48a27c0/pr-7133--ambiguous-general.png) ![Full-key label in a narrow, zoomed composer](https://raw.githubusercontent.com/block/buzz/ac262f00de6fe3860bff2f87dc0e98165ed6b651/pr-7133--layout-1.5-composer.png) *Earlier mock-browser captures, not current-head runtime proof. No new before-state capture; screenshots alone do not prove recipient delivery.* **Clipboard trust:** generated full-key-qualified mentions now retain their exact recipient after copy/paste when the full key matches the clipboard record and community directory/profile state independently vouches for the base alias, including numeric collision suffixes. A qualifier alone does not establish trust. Arbitrary historical labels still cannot always be reconstructed. --------- Signed-off-by: Logan Johnson <[email protected]> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Co-authored-by: Bad Janet <150b20bdf6130418df9239dd1bd082c71612c8d653b47c277200365b9be215dc@buzz> (cherry picked from commit ee883d7) Signed-off-by: nambse <[email protected]>
1 parent 0590b50 commit dce967e

53 files changed

Lines changed: 3612 additions & 465 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎AGENTS.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,3 +772,9 @@ Autocomplete inserts a literal full label and a separator, including multi-word
772772
names. Only autocomplete settlement may move the caret past that separator;
773773
internal label spaces and deliberate ArrowLeft/click movement must be respected.
774774
See `docs/mention-editor.md` and `desktop/tests/e2e/mention-spacing.spec.ts`.
775+
776+
Selected mention labels bind exact keys, including same-name teammates and
777+
persistent automatic addresses. Use the returned label from registration for
778+
insert/restore/remove. Ambiguous manually typed names must fail visibly without
779+
clearing the draft in chat, edit, and standalone forum consumers; never fan out
780+
silently to all identities sharing a name. See `docs/mention-editor.md`.

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export default defineConfig({
8080
"**/mention-spacing.spec.ts",
8181
"**/mention-clipboard.spec.ts",
8282
"**/cloud-provenance.spec.ts",
83+
"**/mention-recipients.spec.ts",
8384
"**/team-mentions.spec.ts",
8485
"**/persistent-agent-audience.spec.ts",
8586
"**/relay-reconnect.spec.ts",

‎desktop/src/features/forum/ui/ForumComposer.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from "react";
22

33
import { EditorContent } from "@tiptap/react";
44
import { ChevronDown } from "lucide-react";
5+
import { toast } from "sonner";
56
import { buildOutgoingMessage } from "@/features/messages/lib/imetaMediaMarkdown";
67
import { useChannelLinks } from "@/features/messages/lib/useChannelLinks";
78
import type { ChannelSuggestion } from "@/features/messages/lib/useChannelLinks";
@@ -280,8 +281,10 @@ export function ForumComposer({
280281
media.setPendingImeta(savedImeta);
281282
if (compact) setIsCompactExpanded(true);
282283
}
283-
} catch {
284-
// Keep the draft intact when authorization refresh fails.
284+
} catch (error) {
285+
// Authorization and ambiguous-name failures must be visible, not a
286+
// silent no-op. This path has not cleared the draft or its selections.
287+
toast.error(error instanceof Error ? error.message : String(error));
285288
} finally {
286289
isSubmissionPendingRef.current = false;
287290
setIsSubmissionPending(false);

‎desktop/src/features/forum/ui/ForumPostCard.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function ForumPostCard({
4949
const { mentionNames, mentionPubkeysByName } = resolveMentionProps(
5050
post.tags,
5151
profiles,
52+
post.content,
5253
);
5354
// Memoize the imeta map: `parseImetaTags` builds a fresh object each render,
5455
// and the `Markdown` memo compares `imetaByUrl` by reference. Without this,

‎desktop/src/features/forum/ui/ForumThreadPanel.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function ReplyRow({
8383
const {
8484
mentionNames: replyMentionNames,
8585
mentionPubkeysByName: replyMentionPubkeysByName,
86-
} = resolveMentionProps(reply.tags, profiles);
86+
} = resolveMentionProps(reply.tags, profiles, reply.content);
8787

8888
return (
8989
<div
@@ -210,7 +210,7 @@ export function ForumThreadPanel({
210210
const {
211211
mentionNames: postMentionNames,
212212
mentionPubkeysByName: postMentionPubkeysByName,
213-
} = resolveMentionProps(post.tags, profiles);
213+
} = resolveMentionProps(post.tags, profiles, post.content);
214214
const postAuthorLabel = resolveUserLabel({
215215
pubkey: post.pubkey,
216216
currentPubkey,

‎desktop/src/features/home/lib/inbox.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ export function buildInboxItems({
593593
const { mentionNames, mentionPubkeysByName } = resolveMentionProps(
594594
item.tags,
595595
profiles,
596+
item.content,
596597
);
597598
const channelLabel = groupChannel.name;
598599
const displayItem: FeedItem = {

‎desktop/src/features/home/lib/inboxViewHelpers.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export function toInboxContextMessage(
193193
const { mentionNames, mentionPubkeysByName } = resolveMentionProps(
194194
message.tags ?? [],
195195
context.profiles,
196+
message.body,
196197
);
197198
return {
198199
id: message.id,

‎desktop/src/features/home/ui/FeedSection.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export function FeedSection({
170170
const { mentionNames, mentionPubkeysByName } = resolveMentionProps(
171171
item.tags,
172172
profiles,
173+
item.content,
173174
);
174175

175176
return (

‎desktop/src/features/messages/lib/draftMentionRefs.test.mjs‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,171 @@ test("edit target separates resolved refs from identities missing profiles", ()
115115
]);
116116
assert.deepEqual(target.unresolvedMentionPubkeys, [BOB]);
117117
});
118+
119+
test("draft snapshots and explicit extraction agree on longest selected or typed occurrences", async () => {
120+
const { snapshotDraftMentionRefs } = await import("./draftMentionRefs.ts");
121+
const { extractMentionPubkeys } = await import("./extractMentionPubkeys.ts");
122+
for (const longer of ["Scout Jones", `Scout (${BOB})`, `Scout (${BOB}) 12`]) {
123+
const mentions = new Map([
124+
["Scout", ALICE],
125+
[longer, BOB],
126+
]);
127+
for (const text of [
128+
`@${longer}!`,
129+
`(@${longer})`,
130+
`**@${longer}**`,
131+
`@${longer}, hello`,
132+
]) {
133+
assert.deepEqual(
134+
snapshotDraftMentionRefs(text, mentions, ["Scout"]).map(
135+
(ref) => ref.pubkey,
136+
),
137+
[BOB],
138+
);
139+
assert.deepEqual(
140+
extractMentionPubkeys({
141+
text,
142+
selectedMentions: mentions,
143+
memberCandidates: [],
144+
}),
145+
[BOB],
146+
);
147+
}
148+
}
149+
const members = [{ displayName: "Scout Jones", pubkey: BOB, isMember: true }];
150+
assert.deepEqual(
151+
snapshotDraftMentionRefs(
152+
"@Scout Jones",
153+
new Map([["Scout", ALICE]]),
154+
["Scout"],
155+
members,
156+
),
157+
[],
158+
);
159+
assert.deepEqual(
160+
snapshotDraftMentionRefs("`@Scout`", new Map([["Scout", ALICE]]), []),
161+
[],
162+
);
163+
});
164+
165+
test("historical ambiguous aliases fail closed and untagged qualified keys do not hydrate", () => {
166+
const same = {
167+
[ALICE]: { displayName: "Scout" },
168+
[BOB]: { displayName: "Scout" },
169+
};
170+
const ambiguous = buildEditMentionState(
171+
"@Scout hello",
172+
[
173+
["p", ALICE],
174+
["p", BOB],
175+
],
176+
same,
177+
() => false,
178+
);
179+
assert.deepEqual(ambiguous.mentionRefs, []);
180+
assert.deepEqual(ambiguous.unresolvedMentionPubkeys, [ALICE, BOB]);
181+
const untrusted = buildEditMentionState(
182+
`@Other (${BOB})`,
183+
[["p", ALICE]],
184+
same,
185+
() => false,
186+
);
187+
assert.deepEqual(untrusted.mentionRefs, []);
188+
const renamed = buildEditMentionState(
189+
`@Old Scout (${BOB}) 12!`,
190+
[["mention", BOB]],
191+
undefined,
192+
() => true,
193+
);
194+
assert.deepEqual(renamed.mentionRefs, [
195+
{ displayName: `Old Scout (${BOB}) 12`, pubkey: BOB, isAgent: true },
196+
]);
197+
});
198+
199+
test("an unbound qualified label cannot fall back to a shorter recipient", async () => {
200+
const { snapshotDraftMentionRefs } = await import("./draftMentionRefs.ts");
201+
const { extractMentionPubkeys } = await import("./extractMentionPubkeys.ts");
202+
const { buildMentionPattern } = await import(
203+
"../../../shared/lib/mentionPattern.ts"
204+
);
205+
const bindings = new Map([["Scout", ALICE]]);
206+
const text = `@Scout (${BOB}) hello`;
207+
assert.deepEqual(snapshotDraftMentionRefs(text, bindings, []), []);
208+
assert.deepEqual(
209+
extractMentionPubkeys({
210+
text,
211+
selectedMentions: bindings,
212+
memberCandidates: [],
213+
}),
214+
[],
215+
);
216+
assert.equal(buildMentionPattern(["Scout"]).test(text), false);
217+
assert.deepEqual(
218+
buildEditMentionState(
219+
text,
220+
[["p", ALICE]],
221+
{ [ALICE]: { displayName: "Scout" } },
222+
() => false,
223+
).mentionRefs,
224+
[],
225+
);
226+
});
227+
228+
test("one-shot persona label iterators still shadow shorter selected recipients", async () => {
229+
const { snapshotDraftMentionRefs } = await import("./draftMentionRefs.ts");
230+
const { extractMentionPubkeys } = await import("./extractMentionPubkeys.ts");
231+
const bindings = new Map([["Scout", ALICE]]);
232+
const personas = new Map([["Scout Jones", "persona-id"]]);
233+
assert.deepEqual(
234+
snapshotDraftMentionRefs(
235+
"@Scout Jones",
236+
bindings,
237+
["Scout"],
238+
[],
239+
personas.keys(),
240+
),
241+
[],
242+
);
243+
assert.deepEqual(
244+
extractMentionPubkeys({
245+
text: "@Scout Jones",
246+
selectedMentions: bindings,
247+
selectedDisplayNames: personas.keys(),
248+
memberCandidates: [],
249+
}),
250+
[],
251+
);
252+
});
253+
254+
test("qualified history consumes the entire multi-digit collision suffix", () => {
255+
for (const suffix of [2, 12, 22, 99, 222]) {
256+
const displayName = `Old Scout (${BOB}) ${suffix}`;
257+
const state = buildEditMentionState(
258+
`@${displayName}!`,
259+
[["mention", BOB]],
260+
undefined,
261+
() => true,
262+
);
263+
assert.deepEqual(state.mentionRefs, [
264+
{ displayName, pubkey: BOB, isAgent: true },
265+
]);
266+
}
267+
});
268+
269+
test("authoritative edit snapshots exclude old p-tags and annotated tray metadata on reopen", () => {
270+
const target = buildEditMentionState(
271+
"@Bob edited",
272+
[
273+
["p", ALICE],
274+
["mention", ALICE, "agent-address"],
275+
["mention", BOB],
276+
["buzz:mention-snapshot"],
277+
],
278+
{ [ALICE]: { displayName: "Alice" }, [BOB]: { displayName: "Bob" } },
279+
() => false,
280+
);
281+
assert.deepEqual(target.mentionRefs, [
282+
{ displayName: "Bob", pubkey: BOB, isAgent: false },
283+
]);
284+
assert.deepEqual(target.unresolvedMentionPubkeys, []);
285+
});

0 commit comments

Comments
 (0)