Skip to content

Commit e2f29cc

Browse files
matt2eclaude
andauthored
feat(messages): open the sender's profile from the byline name (#2253)
## Problem In channels, DMs and threads, clicking a message's avatar opened the sender's profile, but clicking their name did nothing. At the top of a group of messages the name is the only identity element, so people click it and nothing happens. ## Change - The byline name (plus the robot mark for agents) is a `role="button"` span that opens the same profile as the avatar, on click, Enter or Space. It is interactive only where the avatar is clickable, and not on stacked continuation rows. The status and the "X's agent" label stay outside it. - `tabIndex={-1}`, so the avatar stays the group's only tab stop. The name has no hover preview; ProfilePeek stays on the avatar. - At rest the name looks exactly as before. A fine pointer's hover or keyboard `:focus-visible` adds an underline and the pointer cursor, and focus also gets the shared focus ring. - You can still start a text selection on the name, and copied text stays plain. A click that ends a selection (a drag, or the second click of a double-click) doesn't open the profile. - On a short received message, the floating action bar covered the name. It now moves to the side of the name that has room. A hover-clearance band between the bubble and the bar keeps the bar reachable. Own (mirrored) rows are unchanged. - `docs/profiles.md` now lists the byline name as a way to open a profile. ## Before and after Left is before (`90ce5e37a`) and right is after (`c646f3707`), in headless Chromium on the fixture app in light theme. Watch the pointer hover and then click "Priya Shah": only the right side underlines the name and opens the profile. Clicking the avatar opens it in both. The pointer is drawn by an overlay. https://github.com/user-attachments/assets/5a3d3f5c-0f57-4368-ace6-0e415ab940d0 <details> <summary>Stills</summary> ![Hovering the name: before shows a text cursor and no change; after shows a pointing hand and an underline](https://github.com/user-attachments/assets/6d270a69-6afc-4fc9-bdee-dcc80506275f) ![After clicking the name: before still shows only the conversation; after shows Priya Shah's profile docked on the right](https://github.com/user-attachments/assets/18978911-f037-4cfc-bbcb-558440da6fb6) </details> ## Testing Local macOS, at `c646f3707`: - **Vitest:** 2,351 tests in the messages suite pass, including the new `MessageRow.test.tsx` cases for click, Enter and Space, selection, and when the name is interactive. - **Static checks:** typecheck, Biome lint and `design:check` are clean, and the pre-push hooks passed. - **Browser:** eight affected specs, run in Chromium and WebKit with `--no-deps` (profiles, profile-channel-focus, message-avatar-stacking, avatar-shapes, user-status, membership, message-actions-floating, message-selection). 67 of 68 passed. The one failure was WebKit `profiles.spec.mjs:121` ("Close before successor reply resolution…"), which this branch doesn't touch. It passed 3 of 3 when rerun on its own. - **New browser cases:** these need real layout, pointer paths or native selection, which jsdom can't provide. - `message-actions-floating.spec.mjs`: on the first message of a group, a short received one, the bar sits beside the name, a slow diagonal reaches both end buttons, and the name underneath still opens the profile. - `message-selection.spec.mjs`: a drag within the name selects it without opening the profile, and a drag from the name into the body selects both. - **Not checked:** the native Tauri desktop app (WKWebView), and dark theme, narrow widths and enlarged text in the app. This PR stays a draft until a human has tried it. ## Design notes for reviewers - **Design exception:** `.authorLink` in `Messages.module.css` is a quiet link style local to this feature. It doesn't use `InlineReference`'s `.link` because the shared style makes the first byline of each group 3 px taller (16 → 19 px). A suggested follow-up is a quiet variant in `InlineReference` that this byline could adopt. - **Known edge:** if a row becomes a stacked continuation while its profile tab is open, closing the tab has nothing to return focus to. Other places in the app already behave this way, and the impact is low. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Matt Toohey <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent cfd3b95 commit e2f29cc

7 files changed

Lines changed: 319 additions & 12 deletions

File tree

‎docs/profiles.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ performs DNS verification. Ordinary human profiles have no agent fields.
5656

5757
## Boundaries
5858

59-
- Shared message UI recognizes author-avatar targets and identity-bound mentions.
59+
- Shared message UI recognizes author-avatar and byline-name targets and
60+
identity-bound mentions.
6061
Ordinary `canOpenLink` / `onOpenLink` props advertise availability and dispatch.
6162
Channels resolves active contributions at click time and owns the right slot.
6263
- `nostr:npub…` is the exact public-key target, with no relay hint or authority.

‎src/features/messages/MessageRow.test.tsx‎

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,107 @@ it("tells link handlers the thread a reply was opened from", () => {
193193
}
194194
});
195195

196+
it.each([
197+
{ agentEnvelope: false, scheme: "nostr:npub1" },
198+
{ agentEnvelope: true, scheme: "buzz:agent-profile:" },
199+
])(
200+
"opens the author's profile from the byline name: %j",
201+
({ agentEnvelope, scheme }) => {
202+
const authorId = "ab".repeat(32);
203+
const open = vi.fn(() => true);
204+
try {
205+
renderMessage({
206+
row: {
207+
...row,
208+
authorId,
209+
...(agentEnvelope ? { agentEnvelope: true as const } : {}),
210+
},
211+
profile: { name: "Mic" },
212+
onOpenLink: open,
213+
canOpenLink: () => true,
214+
});
215+
const name = screen.getByRole("button", { name: "Mic" });
216+
// Text with a role, so a selection can start on it; the avatar stays
217+
// the group's only tab stop.
218+
expect(name.tagName).toBe("SPAN");
219+
expect(name).toHaveAttribute("tabindex", "-1");
220+
expect(name).not.toHaveAttribute("data-profile-target");
221+
fireEvent.click(name);
222+
// Focused first, so closing the profile can return here.
223+
expect(name).toHaveFocus();
224+
const target = profileTarget(authorId, { agent: agentEnvelope });
225+
expect(target?.startsWith(scheme)).toBe(true);
226+
expect(open).toHaveBeenCalledExactlyOnceWith(target, { rootId: "root" });
227+
} finally {
228+
cleanup();
229+
}
230+
},
231+
);
232+
233+
it("treats a click that selected the name as a selection, and opens from Enter or Space", () => {
234+
const open = vi.fn(() => true);
235+
try {
236+
renderMessage({
237+
row: { ...row, authorId: "ab".repeat(32) },
238+
profile: { name: "Mic" },
239+
onOpenLink: open,
240+
canOpenLink: () => true,
241+
});
242+
const name = screen.getByRole("button", { name: "Mic" });
243+
const selection = document.getSelection();
244+
if (!selection) throw new Error("jsdom selection missing");
245+
// A double-click or drag leaves the name selected when the click lands.
246+
selection.selectAllChildren(name);
247+
fireEvent.click(name);
248+
expect(open).not.toHaveBeenCalled();
249+
selection.removeAllRanges();
250+
fireEvent.click(name);
251+
expect(open).toHaveBeenCalledTimes(1);
252+
fireEvent.keyDown(name, { key: "a" });
253+
expect(open).toHaveBeenCalledTimes(1);
254+
fireEvent.keyDown(name, { key: "Enter" });
255+
// Space must not also scroll the timeline: the default is cancelled.
256+
expect(fireEvent.keyDown(name, { key: " " })).toBe(false);
257+
expect(open).toHaveBeenCalledTimes(3);
258+
} finally {
259+
cleanup();
260+
}
261+
});
262+
263+
it("keeps the byline name plain where profiles cannot open or the byline is screen-reader only", () => {
264+
const props = {
265+
row: { ...row, authorId: "ab".repeat(32) },
266+
profile: { name: "Mic" },
267+
canOpenLink: () => true,
268+
};
269+
try {
270+
const { rerender } = renderMessage({
271+
...props,
272+
canOpenLink: () => false,
273+
});
274+
expect(screen.getByText("Mic").closest('[role="button"]')).toBeNull();
275+
rerender(
276+
<MessageRow
277+
{...props}
278+
media={() => undefined}
279+
onOpenLink={() => true}
280+
day={false}
281+
retry={undefined}
282+
stackPrevious
283+
/>,
284+
);
285+
// The continuation still has its avatar, but its byline is text only.
286+
expect(
287+
screen.getByRole("button", { name: "View Mic profile" }),
288+
).toBeInTheDocument();
289+
const name = screen.getByText("Mic");
290+
expect(name.closest(".sr-only")).toBeInTheDocument();
291+
expect(name.closest('[role="button"]')).toBeNull();
292+
} finally {
293+
cleanup();
294+
}
295+
});
296+
196297
it("keeps plain agent presence without avatar activity, and omits human presence from messages", () => {
197298
const agentRow = { ...row, authorId: "a".repeat(64) };
198299
const subscribe = vi.fn(() => () => {});
@@ -2193,7 +2294,11 @@ it("presents automation, links the owner and discloses the separate relay signer
21932294
onOpenLink: open,
21942295
canOpenLink: () => true,
21952296
});
2196-
expect(screen.getByText("Workflow")).toBeTruthy();
2297+
// The automation label stays plain; only the owner opens a profile.
2298+
expect(
2299+
screen.getByText("Workflow").closest('button, [role="button"]'),
2300+
).toBeNull();
2301+
expect(screen.queryByRole("button", { name: "Wes" })).toBeNull();
21972302
expect(document.querySelector("[data-viewer-message]")).toBeNull();
21982303
expect(document.querySelector("[data-own]")).toBeNull();
21992304
fireEvent.click(

‎src/features/messages/MessageRow.tsx‎

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,15 @@ function MessageRowContent({
545545
: layout === "timeline"
546546
? "default"
547547
: "small";
548+
const authorName = (
549+
<>
550+
{/* Inside the name, so the byline keeps the text baseline. */}
551+
{agentAuthor && !stackPrevious && (
552+
<RobotIcon aria-hidden="true" className={styles.authorAgentIcon} />
553+
)}
554+
{name}
555+
</>
556+
);
548557
const avatar = row.workflowOwnerId ? (
549558
<span className={styles.nestedAvatar}>
550559
<Avatar
@@ -947,14 +956,42 @@ function MessageRowContent({
947956
) : (
948957
<span className={styles.authorWithStatus}>
949958
<strong className={styles.author}>
950-
{/* Inside the name, so the byline keeps the text baseline. */}
951-
{agentAuthor && !stackPrevious && (
952-
<RobotIcon
953-
aria-hidden="true"
954-
className={styles.authorAgentIcon}
955-
/>
959+
{clickable && !stackPrevious ? (
960+
// The avatar is the group's keyboard stop and preview;
961+
// the name only answers a click. Text, not a button, so
962+
// a selection can start on it and a copy keeps it as
963+
// plain prose (no profile target).
964+
// biome-ignore lint/a11y/useSemanticElements: a <button> would block starting a text selection on the name
965+
<span
966+
role="button"
967+
tabIndex={-1}
968+
data-message-author=""
969+
className={styles.authorLink}
970+
onClick={(event) => {
971+
// A click arriving with text selected (the end of
972+
// a drag, or the second click of a double-click)
973+
// is a selection, not a request. A double-click's
974+
// first click opens the profile like any click.
975+
const selection =
976+
event.currentTarget.ownerDocument.getSelection();
977+
if (selection && !selection.isCollapsed) return;
978+
// WebKit skips focusing on pointer click, so the
979+
// profile tab's close would have no origin.
980+
event.currentTarget.focus();
981+
openLink(target);
982+
}}
983+
onKeyDown={(event) => {
984+
if (event.key !== "Enter" && event.key !== " ")
985+
return;
986+
event.preventDefault();
987+
openLink(target);
988+
}}
989+
>
990+
{authorName}
991+
</span>
992+
) : (
993+
authorName
956994
)}
957-
{name}
958995
</strong>
959996
{session && !stackPrevious && (
960997
<UserStatusDisplay

‎src/features/messages/Messages.module.css‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,23 @@
210210
min-width: 0;
211211
max-width: 100%;
212212
}
213+
/* The name opens a profile but stays the byline's text at rest; the link
214+
shows only under a fine pointer or keyboard focus. */
215+
.authorLink {
216+
cursor: pointer;
217+
}
218+
@media (hover: hover) and (pointer: fine) {
219+
.authorLink:hover {
220+
color: var(--text-link);
221+
text-decoration: underline;
222+
}
223+
}
224+
html[data-keyboard-navigation] .authorLink:focus-visible {
225+
color: var(--text-link);
226+
text-decoration: underline;
227+
outline: 2px solid var(--border-focus);
228+
outline-offset: 2px;
229+
}
213230
.authorAgentIcon {
214231
display: inline-block;
215232
width: 1em;

‎src/features/messages/useFloatingActionBar.ts‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export function useFloatingActionBar(
103103
const contentBounds = useRef<{
104104
content: DOMRect;
105105
toolbar: DOMRect;
106+
/** Byline band from the content to a bar moved off the author's name. */
107+
clearance: DOMRect | null;
106108
} | null>(null);
107109

108110
useEffect(() => {
@@ -133,7 +135,7 @@ export function useFloatingActionBar(
133135
!row.contains(target)
134136
)
135137
return false;
136-
const { content, toolbar } = bounds;
138+
const { content, toolbar, clearance } = bounds;
137139
const { clientX: x, clientY: y } = event;
138140
if (
139141
target.closest("[data-message-payload]") &&
@@ -143,6 +145,17 @@ export function useFloatingActionBar(
143145
y <= content.bottom
144146
)
145147
return true;
148+
// A bar moved off the author's name no longer meets the content's top
149+
// edge: the byline band from the content to the bar keeps the hover on
150+
// the way to either end.
151+
if (
152+
clearance &&
153+
x >= clearance.left &&
154+
x <= clearance.right &&
155+
y >= clearance.top &&
156+
y <= clearance.bottom
157+
)
158+
return true;
146159
// Browser hit testing can round a fractional toolbar edge inward.
147160
// Keep the active path through that edge pixel until the bar takes over.
148161
const toolbarBottom = Math.floor(toolbar.bottom);
@@ -322,6 +335,10 @@ export function useFloatingActionBar(
322335
Math.max(whole.bottom, rect.bottom) - top,
323336
);
324337
}
338+
// The author's name opens a profile; the bar must not cover it.
339+
const author = row
340+
.querySelector("[data-message-author]")
341+
?.getBoundingClientRect();
325342
if (covered(anchor)) {
326343
hide();
327344
return;
@@ -376,10 +393,33 @@ export function useFloatingActionBar(
376393
bar.style.clipPath =
377394
hidden > 0 ? `inset(${hidden}px -100vmax -100vmax)` : "";
378395
const left = rtl ? whole.left - overlap : whole.right - width + overlap;
379-
const placedLeft = Math.max(start, Math.min(left, end - width));
396+
// Over a short message the bar would cover the name, so it clears the
397+
// name on the side with room. A mirrored row keeps its place: its bar
398+
// already ends at the avatar.
399+
const cleared =
400+
author?.width &&
401+
author.bottom > paintedTop &&
402+
author.top < top &&
403+
!row.hasAttribute("data-viewer-message")
404+
? rtl
405+
? Math.min(left, author.left - gap - width)
406+
: Math.max(left, author.right + gap)
407+
: left;
408+
const placedLeft = Math.max(start, Math.min(cleared, end - width));
409+
const toolbar = new DOMRect(placedLeft, paintedTop, width, height);
410+
const clearanceLeft = Math.min(whole.left, toolbar.left);
380411
contentBounds.current = {
381412
content: whole,
382-
toolbar: new DOMRect(placedLeft, paintedTop, width, height),
413+
toolbar,
414+
clearance:
415+
cleared === left
416+
? null
417+
: new DOMRect(
418+
clearanceLeft,
419+
paintedTop,
420+
Math.max(whole.right, toolbar.right) - clearanceLeft,
421+
height,
422+
),
383423
};
384424
bar.style.top = `${top}px`;
385425
bar.style.left = `${placedLeft}px`;

‎tests/browser/message-actions-floating.spec.mjs‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,64 @@ for (const own of [true, false]) {
221221

222222
// Browser-only: caption and attachment content share one raised action position
223223
// while retaining native hit testing and an uninterrupted pointer path.
224+
// A first-of-group received message's name opens the sender's profile, so the
225+
// bar moves off it. Browser-only: whether a bar beside the bubble still meets
226+
// a slow diagonal, and whether the name beneath takes the click, are top-layer
227+
// hit tests on measured geometry.
228+
test("actions clear a short received message's name and stay reachable beside it", async ({
229+
page,
230+
app,
231+
}) => {
232+
await open(page, app);
233+
// An own message first, so the received "ok" starts a group with a byline.
234+
app.append("primary", "alpha", "Mine", true, true);
235+
const event = app.append("primary", "alpha", "ok", true, false);
236+
const row = page.locator(
237+
`[data-channel-timeline] [data-message-id="${event.id}"]`,
238+
);
239+
const actions = actionsFor(row);
240+
const name = row.locator("strong > [role='button']");
241+
await expect(name).toBeVisible();
242+
await settle(page);
243+
await hoverMessage(row);
244+
await shown(actions);
245+
await actions.evaluate((bar) =>
246+
Promise.all(bar.getAnimations().map((animation) => animation.finished)),
247+
);
248+
const [nameBox, bar] = await Promise.all([
249+
name.boundingBox(),
250+
actions.boundingBox(),
251+
]);
252+
// The bar is at the name's height but entirely beside it.
253+
expect(bar.y + bar.height).toBeGreaterThan(nameBox.y);
254+
expect(bar.x).toBeGreaterThan(nameBox.x + nameBox.width);
255+
// A slow diagonal from the bubble crosses the byline to either end.
256+
for (const label of ["Add reaction", "More message actions"]) {
257+
await hoverMessage(row);
258+
const button = await actions
259+
.getByRole("button", { name: label, exact: true })
260+
.boundingBox();
261+
await page.mouse.move(
262+
button.x + button.width / 2,
263+
button.y + button.height / 2,
264+
{ steps: 30 },
265+
);
266+
await shown(actions);
267+
}
268+
// The byline keeps the hover only: with the bar shown, the name itself
269+
// still takes the click and opens the profile.
270+
await hoverMessage(row);
271+
await name.hover();
272+
await shown(actions);
273+
const author = await name.innerText();
274+
await name.click();
275+
await expect(
276+
page
277+
.getByRole("complementary", { name: "Profile", exact: true })
278+
.getByRole("heading", { name: author, exact: true }),
279+
).toBeVisible();
280+
});
281+
224282
for (const own of [false, true]) {
225283
test(`captioned ${own ? "own" : "received"} attachments keep their actions reachable`, async ({
226284
page,

0 commit comments

Comments
 (0)