Skip to content

Commit 4f93d52

Browse files
klopez4212wesbillmanPinky
authored
Fix mention chip alignment (#1094)
Signed-off-by: Wes <[email protected]> Co-authored-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent a4fbebb commit 4f93d52

8 files changed

Lines changed: 109 additions & 37 deletions

File tree

‎desktop/src/features/channels/readState/readStateManager.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
resolveEffectiveTimestamp,
77
} from "./readStateManager.ts";
88

9-
const threadKey = "thread:" + "a".repeat(64);
9+
const threadKey = `thread:${"a".repeat(64)}`;
1010
const channelKey = "channel-1";
1111
const channelResolver = (ctx) =>
1212
ctx.startsWith("thread:") ? channelKey : null;

‎desktop/src/features/messages/ui/SystemMessageRow.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { isPositiveEmojiParticle } from "@/shared/ui/EmojiBurstProvider";
1616
import {
1717
MENTION_CHIP_BASE_CLASSES,
1818
MENTION_CHIP_HOVER_CLASSES,
19+
MENTION_CHIP_PREFIX_CLASS,
20+
MESSAGE_MARKDOWN_CLASS,
1921
} from "@/shared/ui/mentionChip";
2022
import { Popover, PopoverContent, PopoverTrigger } from "@/shared/ui/popover";
2123
import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui/tooltip";
@@ -91,7 +93,9 @@ function ProfileName({
9193
: "rounded-xs transition-colors hover:text-foreground",
9294
)}
9395
>
94-
{highlight && !isAgentMention ? "@" : null}
96+
{highlight && !isAgentMention ? (
97+
<span className={MENTION_CHIP_PREFIX_CLASS}>@</span>
98+
) : null}
9599
{children}
96100
</span>
97101
);
@@ -343,7 +347,7 @@ export const SystemMessageRow = React.memo(function SystemMessageRow({
343347
profiles={profiles}
344348
targetPubkey={payload.target}
345349
/>
346-
<div className="min-w-0 flex-1">
350+
<div className={cn(MESSAGE_MARKDOWN_CLASS, "min-w-0 flex-1")}>
347351
<div className="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5">
348352
<div className="truncate text-sm font-semibold leading-none tracking-tight text-foreground">
349353
{description.title}

‎desktop/src/features/messages/ui/useTimelineScrollManager.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ export function useTimelineScrollManager({
395395
[onTargetReached, unpinFromBottom],
396396
);
397397

398-
// biome-ignore lint/correctness/useExhaustiveDependencies: timelineRef is a stable React ref — its identity never changes
399398
React.useEffect(() => {
400399
if (!targetMessageId) {
401400
handledTargetMessageIdRef.current = null;

‎desktop/src/shared/styles/globals.css‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,12 @@
896896
color: hsl(var(--primary));
897897
}
898898

899+
.message-markdown .mention-chip-prefix {
900+
display: inline-block;
901+
line-height: 1;
902+
transform: translateY(-0.12em);
903+
}
904+
899905
.message-markdown .inline-code-chip,
900906
.message-markdown :not(pre) > code {
901907
font-size: var(--inline-code-font-size);

‎desktop/src/shared/ui/markdown.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
INLINE_CODE_CHIP_CLASS,
4747
MENTION_CHIP_BASE_CLASSES,
4848
MENTION_CHIP_HOVER_CLASSES,
49+
MENTION_CHIP_PREFIX_CLASS,
4950
MESSAGE_MARKDOWN_CLASS,
5051
} from "@/shared/ui/mentionChip";
5152
import { Popover, PopoverContent, PopoverTrigger } from "@/shared/ui/popover";
@@ -1941,9 +1942,15 @@ function createMarkdownComponents(
19411942
const isAgentMention =
19421943
pubkey !== undefined &&
19431944
agentMentionPubkeysByName?.[mentionName] === pubkey;
1944-
const renderedMentionText = isAgentMention
1945-
? mentionText.replace(/^@/, "")
1946-
: children;
1945+
const mentionLabel = mentionText.replace(/^@/, "");
1946+
const renderedMentionText = isAgentMention ? (
1947+
mentionLabel
1948+
) : (
1949+
<>
1950+
<span className={MENTION_CHIP_PREFIX_CLASS}>@</span>
1951+
{mentionLabel}
1952+
</>
1953+
);
19471954
const mentionNode = (
19481955
<span
19491956
data-mention=""

‎desktop/src/shared/ui/mentionChip.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export const MENTION_CHIP_BASE_CLASSES = "mention-chip";
22

33
export const MENTION_CHIP_HOVER_CLASSES = "mention-chip-hover";
44

5+
export const MENTION_CHIP_PREFIX_CLASS = "mention-chip-prefix";
6+
57
/** Wrapper on rendered message Markdown — scopes inline chip CSS. */
68
export const MESSAGE_MARKDOWN_CLASS = "message-markdown";
79

‎desktop/tests/e2e/mentions.spec.ts‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,49 @@ test("system add and remove rows use agent mention styling for managed agents",
699699
).toHaveText("portal");
700700
});
701701

702+
test("system member-joined rows render the joined person as a mention chip", async ({
703+
page,
704+
}) => {
705+
await page.goto("/");
706+
await page.getByTestId("channel-general").click();
707+
await expect(page.getByTestId("chat-title")).toHaveText("general");
708+
await waitForMockLiveSubscription(page, "general", SYSTEM_MESSAGE_KIND);
709+
710+
await page.evaluate(
711+
({ kind, pubkey }) => {
712+
window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
713+
channelName: "general",
714+
content: JSON.stringify({
715+
type: "member_joined",
716+
actor: pubkey,
717+
target: pubkey,
718+
}),
719+
kind,
720+
});
721+
},
722+
{ kind: SYSTEM_MESSAGE_KIND, pubkey: TEST_IDENTITIES.bob.pubkey },
723+
);
724+
await waitForTimelineSettled(page);
725+
726+
const joinedRow = page
727+
.getByTestId("system-message-row")
728+
.filter({ hasText: "bob" })
729+
.filter({ hasText: "joined the channel" });
730+
const joinedPersonChip = joinedRow.locator("[data-mention].mention-chip", {
731+
hasText: "bob",
732+
});
733+
734+
await expect(joinedPersonChip).toBeVisible();
735+
await expect(joinedPersonChip).toHaveCSS("display", /^(inline-)?flex$/);
736+
await expect(joinedPersonChip).not.toHaveCSS(
737+
"background-color",
738+
"rgba(0, 0, 0, 0)",
739+
);
740+
await expect(joinedPersonChip.locator(".mention-chip-prefix")).toHaveText(
741+
"@",
742+
);
743+
});
744+
702745
test("selecting a non-member agent from a DM inserts @Name into input", async ({
703746
page,
704747
}) => {
@@ -988,7 +1031,7 @@ test("Escape dismisses autocomplete dropdown", async ({ page }) => {
9881031
});
9891032

9901033
test("mention text is highlighted in sent messages", async ({ page }) => {
991-
const suffix = `check this out ${Date.now()}`;
1034+
const suffix = ` check this out ${Date.now()}`;
9921035

9931036
await page.goto("/");
9941037
await page.getByTestId("channel-general").click();
@@ -1006,8 +1049,9 @@ test("mention text is highlighted in sent messages", async ({ page }) => {
10061049
const mentionChip = page
10071050
.getByTestId("message-row")
10081051
.last()
1009-
.locator("[data-mention]", { hasText: "@bob" });
1052+
.locator("[data-mention].mention-chip", { hasText: "bob" });
10101053
await expect(mentionChip).toBeVisible();
1054+
await expect(mentionChip.locator(".mention-chip-prefix")).toHaveText("@");
10111055
await expect(mentionChip.locator("svg")).toHaveCount(0);
10121056
});
10131057

‎desktop/tests/e2e/thread-unread-screenshots.spec.ts‎

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { TEST_IDENTITIES, installMockBridge } from "../helpers/bridge";
44

55
const SHOTS = "test-results/thread-unread";
66

7+
type MockMessageEvent = {
8+
id: string;
9+
created_at: number;
10+
pubkey: string;
11+
};
12+
713
async function waitForMockLiveSubscription(
814
page: import("@playwright/test").Page,
915
channelName: string,
@@ -26,7 +32,7 @@ async function waitForMockLiveSubscription(
2632
.toBe(true);
2733
}
2834

29-
function emitMockMessage(
35+
async function emitMockMessage(
3036
page: import("@playwright/test").Page,
3137
channelName: string,
3238
content: string,
@@ -36,8 +42,8 @@ function emitMockMessage(
3642
createdAt?: number;
3743
mentionPubkeys?: string[];
3844
},
39-
) {
40-
return page.evaluate(
45+
): Promise<MockMessageEvent> {
46+
const event = await page.evaluate(
4147
({ ch, msg, parentEventId, pubkey, ts, mentionPubkeys }) => {
4248
return (
4349
window as Window & {
@@ -68,6 +74,10 @@ function emitMockMessage(
6874
mentionPubkeys: options?.mentionPubkeys,
6975
},
7076
);
77+
if (!event) {
78+
throw new Error("Mock message emitter is not installed");
79+
}
80+
return event;
7181
}
7282

7383
// Unread thread replies must be dated strictly after the read frontier captured
@@ -231,7 +241,7 @@ test.describe("thread unread indicator screenshots", () => {
231241
const base = unreadTimestamp();
232242
for (let i = 0; i < 2; i++) {
233243
await emitMockMessage(page, "general", `Bob chimes in ${i + 1}`, {
234-
parentEventId: rootEvent!.id,
244+
parentEventId: rootEvent.id,
235245
pubkey: TEST_IDENTITIES.bob.pubkey,
236246
createdAt: base + i,
237247
});
@@ -278,19 +288,19 @@ test.describe("thread unread indicator screenshots", () => {
278288
"general",
279289
"Replying one level down",
280290
{
281-
parentEventId: r1!.id,
291+
parentEventId: r1.id,
282292
pubkey: TEST_IDENTITIES.bob.pubkey,
283293
createdAt: past + 1,
284294
},
285295
);
286296
// A sibling at r1's level so the tree reads as a branching discussion.
287297
await emitMockMessage(page, "general", "Separate angle on the same point", {
288-
parentEventId: r1!.id,
298+
parentEventId: r1.id,
289299
pubkey: TEST_IDENTITIES.charlie.pubkey,
290300
createdAt: past + 2,
291301
});
292302
const r3 = await emitMockMessage(page, "general", "Going deeper still", {
293-
parentEventId: r2!.id,
303+
parentEventId: r2.id,
294304
pubkey: TEST_IDENTITIES.alice.pubkey,
295305
createdAt: past + 3,
296306
});
@@ -302,8 +312,8 @@ test.describe("thread unread indicator screenshots", () => {
302312
await expect(summary).toBeVisible();
303313
await summary.click();
304314
await expect(page.getByTestId("message-thread-panel")).toBeVisible();
305-
await expandReply(page, r1!.id);
306-
await expandReply(page, r2!.id);
315+
await expandReply(page, r1.id);
316+
await expandReply(page, r2.id);
307317
await page.getByTestId("message-thread-close").click();
308318
await expect(page.getByTestId("message-thread-panel")).not.toBeVisible();
309319

@@ -314,12 +324,12 @@ test.describe("thread unread indicator screenshots", () => {
314324

315325
const base = unreadTimestamp();
316326
const r4 = await emitMockMessage(page, "general", "New nested follow-up", {
317-
parentEventId: r3!.id,
327+
parentEventId: r3.id,
318328
pubkey: TEST_IDENTITIES.bob.pubkey,
319329
createdAt: base,
320330
});
321331
await emitMockMessage(page, "general", "Deepest unread reply", {
322-
parentEventId: r4!.id,
332+
parentEventId: r4.id,
323333
pubkey: TEST_IDENTITIES.alice.pubkey,
324334
createdAt: base + 1,
325335
});
@@ -331,10 +341,10 @@ test.describe("thread unread indicator screenshots", () => {
331341
await expect(page.getByTestId("chat-title")).toHaveText("general");
332342
await page.getByTestId("message-thread-summary").first().click();
333343
await expect(page.getByTestId("message-thread-panel")).toBeVisible();
334-
await expandReply(page, r1!.id);
335-
await expandReply(page, r2!.id);
336-
await expandReply(page, r3!.id);
337-
await expandReply(page, r4!.id);
344+
await expandReply(page, r1.id);
345+
await expandReply(page, r2.id);
346+
await expandReply(page, r3.id);
347+
await expandReply(page, r4.id);
338348

339349
// Fully expanded: r1, r2, sibling, r3, r4, r5 — six rendered replies.
340350
const replies = page
@@ -371,7 +381,7 @@ test.describe("thread unread indicator screenshots", () => {
371381
createdAt: past,
372382
});
373383
const c = await emitMockMessage(page, "general", "Child of branch parent", {
374-
parentEventId: p!.id,
384+
parentEventId: p.id,
375385
pubkey: TEST_IDENTITIES.bob.pubkey,
376386
createdAt: past + 1,
377387
});
@@ -402,13 +412,13 @@ test.describe("thread unread indicator screenshots", () => {
402412
"general",
403413
"Unread under the branch",
404414
{
405-
parentEventId: c!.id,
415+
parentEventId: c.id,
406416
pubkey: TEST_IDENTITIES.alice.pubkey,
407417
createdAt: base,
408418
},
409419
);
410420
await emitMockMessage(page, "general", "Another unread under the branch", {
411-
parentEventId: c2!.id,
421+
parentEventId: c2.id,
412422
pubkey: TEST_IDENTITIES.bob.pubkey,
413423
createdAt: base + 1,
414424
});
@@ -444,7 +454,7 @@ test.describe("thread unread indicator screenshots", () => {
444454

445455
// Expanding p marks its whole subtree read; the descendant-inclusive gate
446456
// (Phase 2.5) drops the badge from p and every revealed row beneath it.
447-
await expandReply(page, p!.id);
457+
await expandReply(page, p.id);
448458
await expect(inPanelBadge).toHaveCount(0);
449459

450460
await page.screenshot({
@@ -469,7 +479,7 @@ test.describe("thread unread indicator screenshots", () => {
469479
createdAt: past,
470480
});
471481
const c = await emitMockMessage(page, "general", "Child of branch parent", {
472-
parentEventId: p!.id,
482+
parentEventId: p.id,
473483
pubkey: TEST_IDENTITIES.bob.pubkey,
474484
createdAt: past + 1,
475485
});
@@ -486,7 +496,7 @@ test.describe("thread unread indicator screenshots", () => {
486496

487497
const base = unreadTimestamp();
488498
await emitMockMessage(page, "general", "First unread under branch", {
489-
parentEventId: c!.id,
499+
parentEventId: c.id,
490500
pubkey: TEST_IDENTITIES.alice.pubkey,
491501
createdAt: base,
492502
});
@@ -508,7 +518,7 @@ test.describe("thread unread indicator screenshots", () => {
508518
// the badge must bump to 2 on the same tick — readStateVersion-driven
509519
// recompute is what makes this fire live rather than on a later re-render.
510520
await emitMockMessage(page, "general", "Second unread under branch", {
511-
parentEventId: c!.id,
521+
parentEventId: c.id,
512522
pubkey: TEST_IDENTITIES.bob.pubkey,
513523
createdAt: base + 1,
514524
});
@@ -538,7 +548,7 @@ test.describe("thread unread indicator screenshots", () => {
538548
createdAt: past,
539549
});
540550
const oldChild = await emitMockMessage(page, "general", "Old child", {
541-
parentEventId: branchOld!.id,
551+
parentEventId: branchOld.id,
542552
pubkey: TEST_IDENTITIES.bob.pubkey,
543553
createdAt: past + 1,
544554
});
@@ -548,7 +558,7 @@ test.describe("thread unread indicator screenshots", () => {
548558
createdAt: past + 2,
549559
});
550560
const newChild = await emitMockMessage(page, "general", "New child", {
551-
parentEventId: branchNew!.id,
561+
parentEventId: branchNew.id,
552562
pubkey: TEST_IDENTITIES.alice.pubkey,
553563
createdAt: past + 3,
554564
});
@@ -570,12 +580,12 @@ test.describe("thread unread indicator screenshots", () => {
570580
// sibling's badge survives until that branch is expanded too.
571581
const base = unreadTimestamp();
572582
await emitMockMessage(page, "general", "Unread in older branch", {
573-
parentEventId: oldChild!.id,
583+
parentEventId: oldChild.id,
574584
pubkey: TEST_IDENTITIES.alice.pubkey,
575585
createdAt: base,
576586
});
577587
await emitMockMessage(page, "general", "Unread in newer branch", {
578-
parentEventId: newChild!.id,
588+
parentEventId: newChild.id,
579589
pubkey: TEST_IDENTITIES.bob.pubkey,
580590
createdAt: base + 30,
581591
});
@@ -599,15 +609,15 @@ test.describe("thread unread indicator screenshots", () => {
599609
// `expandedSubtreeReplyIds` gate against the frozen open-time frontier.
600610
// The older sibling's badge SURVIVES — the design does not sweep across
601611
// branches off a live marker.
602-
await expandReply(page, branchNew!.id);
612+
await expandReply(page, branchNew.id);
603613
await expect(inPanelBadges).toHaveCount(1);
604614

605615
await page.screenshot({
606616
path: `${SHOTS}/09-expand-clears-own-branch-sibling-survives.png`,
607617
});
608618

609619
// Expanding the older branch clears the last remaining badge.
610-
await expandReply(page, branchOld!.id);
620+
await expandReply(page, branchOld.id);
611621
await expect(inPanelBadges).toHaveCount(0);
612622

613623
await page.screenshot({

0 commit comments

Comments
 (0)