Skip to content

Commit 1c81e00

Browse files
matt2eclaude
andcommitted
feat(messages): name the author in message links
A raw Buzz message or thread link now reads "<icon> <author> in #<channel>" instead of only the channel name, in both its visible label and its accessible name. The icon, styling, preview card, menu and click behaviour are unchanged, and selection copy still yields the raw URL. The author comes from the same bounded exact thread reader the hover preview uses; the session exposes no other single-message read. A session-scoped lookup borrows one reader per linked message, disposes it as soon as the author is known, remembers the result for the session, runs at most four at once so open threads and previews keep their capacity, and cancels a lookup when its last link unmounts. Names resolve through the existing identity names, profile names and workflow attribution. The preview now shares its ready/stopped check. The previous channel presentation stays while the author is unknown or unnamed, when the message is unavailable or no reader is free, and for DMs, Solo chats, unlisted channels, authored labels, and composer drafts and previews, which never read. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 9818f77 commit 1c81e00

8 files changed

Lines changed: 524 additions & 44 deletions

File tree

‎docs/plugin-architecture.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,14 +1442,17 @@ credential-free HTTP(S) and supported Buzz links. Markdown labels preserve their
14421442
formatting, escaped pasted wrappers are normalized outside code, and paired `<…>`
14431443
autolink wrappers are hidden in display. Buzz links use known channel names with corresponding icons, falling back
14441444
to Channel, Message or Thread when that name is unavailable in the current community;
1445-
the full destination remains on the anchor. Buzz activation stays inside the host,
1445+
the full destination remains on the anchor. A raw message or thread link in a listed
1446+
channel reads as “<author> in #<channel>” once its author has a name; DMs, Solo chats,
1447+
authored labels and drafts keep the channel name. Buzz activation stays inside the host,
14461448
including modifier/middle clicks, even when the optional Links plugin is disabled.
14471449
Unsupported Buzz formats remain plain text. The host-matched author preview exports `LinkRenderer`; older hosts do not
14481450
provide `registerLink`.
14491451

14501452
Message hover/focus previews are host-owned. The entire card is a keyboard-accessible
14511453
link to the same destination, routed through the same host navigation handler. Opening a preview allocates the current
1452-
session's bounded thread reader; closing disposes it. The reader supplies verified
1454+
session's bounded thread reader; closing disposes it. A live message link borrows
1455+
the same reader only until it learns its author. The reader supplies verified
14531456
message content, author and timestamp and preserves edit/deletion/access handling.
14541457
Previewing never acknowledges reading or switches community. The host offers a
14551458
resolved label to the bundled presentation via `LinkLabelContext`, and whether

‎src/features/conversation/BuzzLinkPreview.tsx‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Avatar } from "../../shared/design-system/ui/Avatar";
1616
import { relativeTimestamp } from "../../shared/relative-timestamp";
1717
import styles from "./LinkPreview.module.css";
1818
import { messagePreviewText } from "./message-preview-text";
19+
import { linkedMessage } from "./linked-message";
1920
import { avatarMedia } from "../../shared/avatar-source";
2021
import { sortParticipantNames } from "../identity-names/participant-order";
2122

@@ -63,11 +64,7 @@ function PreviewContent({
6364
view.snapshot,
6465
view.snapshot,
6566
);
66-
const target =
67-
snapshot.target?.id === messageId ? snapshot.target : undefined;
68-
const message =
69-
target ??
70-
[snapshot.root, ...snapshot.replies].find((row) => row?.id === messageId);
67+
const { message, ready, stopped } = linkedMessage(snapshot, messageId);
7168
const resolveName = useChannelIdentityNames(session, message?.channelId);
7269
const identityName = useIdentityNames(session.names);
7370
const profiles = useSyncExternalStore(
@@ -85,19 +82,6 @@ function PreviewContent({
8582
if (authorId)
8683
void session.profiles.ensure([authorId], "background").catch(() => {});
8784
}, [session, authorId]);
88-
// Only paint reconciled content: a ready exact target is independent of its
89-
// thread root, while an idle/loading root seed is still the raw event.
90-
// A terminal state (read error, denied/interrupted purge, or an exhausted
91-
// read that never found the target) fails honestly instead of loading forever.
92-
const stopped =
93-
snapshot.status === "error" ||
94-
snapshot.targetStatus === "error" ||
95-
snapshot.targetStatus === "unavailable" ||
96-
(snapshot.status === "idle" && snapshot.error !== undefined) ||
97-
(snapshot.status === "ready" && !message && !snapshot.canLoadMore);
98-
const ready = target
99-
? snapshot.targetStatus === "ready"
100-
: snapshot.status === "ready";
10185
if (!ready || !message)
10286
return (
10387
<span role="status">

‎src/features/conversation/MessageLink.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
} from "./LinkLabelContext";
4545
import { BuzzLinkPreview, ChannelLinkPreview } from "./BuzzLinkPreview";
4646
import { useChannelReference } from "./channel-reference";
47+
import { useLinkedMessageByline } from "./linked-message";
4748
import { messageViewKey } from "../messages/view-key";
4849
import { soloChatLinkName } from "../solo/labels";
4950
import styles from "./LinkPreview.module.css";
@@ -151,8 +152,17 @@ export function MessageLink({
151152
// The authored label is message text, so it stays; the lock marks it. A raw
152153
// destination has no name to show.
153154
const shown = withheld && label === undefined ? "Private channel" : children;
155+
// A raw message destination names its author once read; a draft never reads.
156+
const byline = useLinkedMessageByline(
157+
interactive && label === undefined && children === undefined
158+
? host
159+
: undefined,
160+
destination?.channelId,
161+
destination?.messageId,
162+
);
154163
const display =
155164
label ??
165+
byline ??
156166
directoryLabel ??
157167
(named ? `#${named.name}` : withheld ? "Private channel" : undefined);
158168
const [menuOpen, setMenuOpen] = useState(false);
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
// @vitest-environment jsdom
2+
import { act, cleanup, render, screen } from "@testing-library/react";
3+
import { afterEach, expect, it, vi } from "vitest";
4+
import { LinkLabel } from "../../bundled/links/InlineLink";
5+
import type { ChannelMessage, Profile } from "../relay/contracts";
6+
import type { RelaySession } from "../relay/session";
7+
import type { ThreadSnapshot, ThreadView } from "../relay/threads";
8+
import { MessageLink } from "./MessageLink";
9+
10+
afterEach(cleanup);
11+
// Lookups start after the commit that mounted their links.
12+
const started = () => act(async () => {});
13+
14+
const alice = "b".repeat(64);
15+
const id = (n: number) => n.toString(16).padStart(64, "a");
16+
const href = (messageId: string, thread?: string) =>
17+
`buzz://message?${new URLSearchParams({ channel: "design", id: messageId, ...(thread ? { thread } : {}) })}`;
18+
const message = (messageId: string, patch?: Partial<ChannelMessage>) =>
19+
({
20+
id: messageId,
21+
channelId: "design",
22+
authorId: alice,
23+
content: "Linked body",
24+
createdAt: 1,
25+
mentions: [],
26+
participants: [],
27+
attachments: [],
28+
reactions: [],
29+
replyCount: 0,
30+
...patch,
31+
}) satisfies ChannelMessage;
32+
const loading: ThreadSnapshot = {
33+
status: "loading",
34+
root: undefined,
35+
replies: [],
36+
error: undefined,
37+
canLoadMore: true,
38+
limited: false,
39+
targetStatus: "loading",
40+
};
41+
const ready = (target: ChannelMessage): Partial<ThreadSnapshot> => ({
42+
status: "ready",
43+
canLoadMore: false,
44+
target,
45+
targetStatus: "ready",
46+
});
47+
48+
/** Exact readers the test settles by hand; `open` counts undisposed ones. */
49+
function fixture({
50+
channels = [{ id: "design", name: "design" }] as {
51+
id: string;
52+
name: string;
53+
channelType?: string;
54+
}[],
55+
profiles = new Map<string, Profile>([[alice, { name: "Alice" }]]),
56+
capacity = Number.POSITIVE_INFINITY,
57+
} = {}) {
58+
const views: {
59+
messageId: string;
60+
publish(patch: Partial<ThreadSnapshot>): Promise<void>;
61+
disposed: boolean;
62+
}[] = [];
63+
const thread = vi.fn((_channelId: string, messageId: string): ThreadView => {
64+
if (views.filter((view) => !view.disposed).length >= capacity)
65+
throw new Error("Relay view capacity unavailable");
66+
let snapshot = loading;
67+
const listeners = new Set<() => void>();
68+
const entry = {
69+
messageId,
70+
disposed: false,
71+
async publish(patch: Partial<ThreadSnapshot>) {
72+
snapshot = { ...snapshot, ...patch };
73+
await act(async () => {
74+
for (const listener of listeners) listener();
75+
});
76+
},
77+
};
78+
views.push(entry);
79+
return {
80+
snapshot: () => snapshot,
81+
subscribe(listener) {
82+
listeners.add(listener);
83+
return () => void listeners.delete(listener);
84+
},
85+
refresh: async () => {},
86+
loadMore: async () => {},
87+
retarget: async () => "selected",
88+
dispose: () => {
89+
entry.disposed = true;
90+
},
91+
};
92+
});
93+
const profileListeners = new Set<() => void>();
94+
const list = { status: "ready", channels };
95+
const ensure = vi.fn(async () => {});
96+
const session = {
97+
unread: {},
98+
thread,
99+
profiles: {
100+
snapshot: () => profiles,
101+
subscribe(listener: () => void) {
102+
profileListeners.add(listener);
103+
return () => void profileListeners.delete(listener);
104+
},
105+
ensure,
106+
},
107+
channels: { list: () => list, subscribeList: () => () => {} },
108+
media: () => undefined,
109+
} as unknown as RelaySession;
110+
return {
111+
session,
112+
thread,
113+
views,
114+
ensure,
115+
open: () => views.filter((view) => !view.disposed),
116+
async setProfiles(next: Map<string, Profile>) {
117+
profiles = next;
118+
await act(async () => {
119+
for (const listener of profileListeners) listener();
120+
});
121+
},
122+
};
123+
}
124+
const renderers = [
125+
{
126+
id: "link",
127+
title: "Links",
128+
key: "links/link",
129+
pluginId: "links",
130+
revision: "one",
131+
matches: () => true,
132+
component: ({ url }: { url: string }) => <LinkLabel href={url} />,
133+
},
134+
];
135+
const links = { snapshot: () => renderers, subscribe: () => () => {} };
136+
const link = (
137+
session: RelaySession,
138+
url: string,
139+
props?: Partial<Parameters<typeof MessageLink>[0]>,
140+
) => (
141+
<MessageLink
142+
url={url}
143+
directoryLabel="design"
144+
registry={links}
145+
onOpenLink={() => true}
146+
session={session}
147+
{...props}
148+
/>
149+
);
150+
151+
it("names the linked message's author and channel once its exact reader settles", async () => {
152+
const app = fixture();
153+
render(link(app.session, href(id(1))));
154+
await started();
155+
// Loading keeps the existing channel label and icon.
156+
const anchor = screen.getByRole("link", { name: "design" });
157+
expect(anchor.querySelector('[data-link-kind="message"] svg')).not.toBeNull();
158+
expect(app.thread).toHaveBeenCalledWith("design", id(1), { exact: true });
159+
await app.views[0]?.publish(ready(message(id(1))));
160+
expect(screen.getByRole("link", { name: "Alice in #design" })).toBe(anchor);
161+
expect(anchor.textContent).toBe("Alice in #design");
162+
expect(anchor.querySelector('[data-link-kind="message"] svg')).not.toBeNull();
163+
expect(anchor.getAttribute("href")).toBe(href(id(1)));
164+
// Display only: selection copy still reads the raw destination.
165+
expect(anchor.dataset.linkLabel).toBe("");
166+
// The lookup gives its reader back as soon as it has the author.
167+
expect(app.open()).toHaveLength(0);
168+
expect(app.ensure).toHaveBeenCalledWith([alice], "background");
169+
});
170+
171+
it("names a reply's author with the thread icon and a workflow by its owner", async () => {
172+
const app = fixture();
173+
render(
174+
<>
175+
{link(app.session, href(id(1), id(9)))}
176+
{link(app.session, href(id(2)))}
177+
</>,
178+
);
179+
await started();
180+
await app.views[0]?.publish(ready(message(id(1), { threadRootId: id(9) })));
181+
await app.views[1]?.publish(
182+
ready(message(id(2), { authorId: "c".repeat(64), workflowOwnerId: alice })),
183+
);
184+
const reply = screen.getByRole("link", { name: "Alice in #design" });
185+
expect(reply.querySelector('[data-link-kind="thread"] svg')).not.toBeNull();
186+
expect(
187+
screen.getByRole("link", { name: "Workflow · owned by Alice in #design" }),
188+
).toBeTruthy();
189+
});
190+
191+
it("keeps the channel label while the author has no name, and names them once loaded", async () => {
192+
const app = fixture({
193+
profiles: new Map([
194+
[alice, { name: alice.slice(0, 10), nameIsFallback: true }],
195+
]),
196+
});
197+
render(link(app.session, href(id(1))));
198+
await started();
199+
await app.views[0]?.publish(ready(message(id(1))));
200+
expect(screen.getByRole("link", { name: "design" }).textContent).toBe(
201+
"design",
202+
);
203+
await app.setProfiles(new Map([[alice, { name: "Alice" }]]));
204+
expect(screen.getByRole("link", { name: "Alice in #design" })).toBeTruthy();
205+
});
206+
207+
it("keeps the channel label when the message is unavailable or no reader is free", async () => {
208+
const unavailable = fixture();
209+
const view = render(link(unavailable.session, href(id(1))));
210+
await started();
211+
await unavailable.views[0]?.publish({
212+
status: "idle",
213+
targetStatus: "unavailable",
214+
error: "Message unavailable",
215+
});
216+
expect(screen.getByRole("link", { name: "design" })).toBeTruthy();
217+
expect(unavailable.open()).toHaveLength(0);
218+
view.unmount();
219+
const full = fixture({ capacity: 0 });
220+
render(link(full.session, href(id(1))));
221+
await started();
222+
await started();
223+
// A failed lookup waits for a later mount instead of retrying in a loop.
224+
expect(full.thread).toHaveBeenCalledOnce();
225+
expect(screen.getByRole("link", { name: "design" })).toBeTruthy();
226+
});
227+
228+
it("reads nothing for authored labels, drafts, unlisted channels, DMs or Solo chats", async () => {
229+
const app = fixture();
230+
render(
231+
<>
232+
{link(app.session, href(id(1)), { label: "See this" })}
233+
{link(app.session, href(id(2)), { interactive: false })}
234+
</>,
235+
);
236+
await started();
237+
expect(screen.getByRole("link", { name: "See this" })).toBeTruthy();
238+
expect(document.body.textContent).toContain("design");
239+
expect(app.thread).not.toHaveBeenCalled();
240+
cleanup();
241+
for (const channels of [
242+
[],
243+
[{ id: "design", name: "design", channelType: "dm" }],
244+
[{ id: "design", name: "design", channelType: "solo" }],
245+
]) {
246+
const other = fixture({ channels });
247+
render(link(other.session, href(id(3))));
248+
await started();
249+
expect(screen.getByRole("link", { name: "design" })).toBeTruthy();
250+
expect(other.thread).not.toHaveBeenCalled();
251+
cleanup();
252+
}
253+
});
254+
255+
it("runs a few lookups at once, cancels unmounted ones and remembers found authors", async () => {
256+
const app = fixture();
257+
const ids = [1, 2, 3, 4, 5, 6].map(id);
258+
const all = ids.map((messageId) => (
259+
<span key={messageId}>{link(app.session, href(messageId))}</span>
260+
));
261+
const tree = (again: boolean) => (
262+
<>
263+
{all}
264+
{again && <span>{link(app.session, href(ids[1] ?? ""))}</span>}
265+
</>
266+
);
267+
const view = render(tree(false));
268+
await started();
269+
expect(app.open().map((entry) => entry.messageId)).toEqual(ids.slice(0, 4));
270+
await app.views[0]?.publish(ready(message(ids[0] ?? "")));
271+
expect(app.open().map((entry) => entry.messageId)).toEqual(ids.slice(1, 5));
272+
// Two links to one message share its lookup.
273+
view.rerender(tree(true));
274+
await started();
275+
expect(app.thread).toHaveBeenCalledTimes(5);
276+
// Links that unmount together cancel their lookups without starting others.
277+
view.unmount();
278+
await started();
279+
expect(app.open()).toHaveLength(0);
280+
expect(app.thread).toHaveBeenCalledTimes(5);
281+
// A remount shows a found author without reading it again.
282+
render(link(app.session, href(ids[0] ?? "")));
283+
await started();
284+
expect(screen.getByRole("link", { name: "Alice in #design" })).toBeTruthy();
285+
expect(app.thread).toHaveBeenCalledTimes(5);
286+
});

0 commit comments

Comments
 (0)