Skip to content

Commit 0e69b3f

Browse files
show mention counts in channel notifications (#6696)
**Category:** fix **User Impact:** Stream and forum channels now show an accessible numeric badge for unread mentions while mention chips remain clear in every theme. **Problem:** Mention notifications contributed to the app and Dock badge, but inactive stream and forum rows only became bold, making it difficult to see where multiple mentions were waiting. Mention styling and generic destructive colors could also lose contrast or visual meaning in some themes. **Solution:** Use the same app-badge projection for non-DM channel mention counts, while preserving regular unread bolding, thread activity dots, DM counts, and manual unread behavior. Dedicated notification and opaque mention-highlight tokens keep the new treatments stable and readable across syntax themes. <details> <summary>File changes</summary> **desktop/src/features/channels/useUnreadChannels.ts** Projects app-badge-eligible mention and broadcast counts into stream and forum channel rows while retaining DM-specific counting and manual-unread semantics. **desktop/src/features/sidebar/ui/SidebarSection.tsx** Renders an accessible numeric notification pill on inactive non-DM channels and preserves the thread activity dot fallback. **desktop/src/shared/styles/globals/markdown.css** Applies the shared opaque yellow highlight to human and agent mention chips, including hover treatment. **desktop/src/shared/styles/globals/theme.css** Adds fixed notification and mention-highlight tokens with theme-independent contrast. **desktop/tailwind.config.js** Exposes the notification token pair through semantic Tailwind utilities. **desktop/tests/e2e/badge.spec.ts** Covers aggregated mention counts, broadcasts, unchanged unread tiers, exact accessible text, and badge contrast under an adversarial theme. **desktop/tests/e2e/mentions.spec.ts** Covers human and agent mention styling, hover behavior, dark mode, and WCAG text contrast. </details> ## Reproduction steps 1. Open a stream or forum channel, then navigate to another channel. 2. Receive two messages that mention you in the inactive channel. 3. Confirm the inactive row is bold and shows a red `2` pill matching the two notifications added to the app or Dock badge. 4. Receive a regular channel message and confirm the row only becomes bold, without a numeric pill. 5. Receive a reply in an interested thread and confirm the channel retains its activity dot instead of a mention count. 6. Switch between light and dark themes and confirm human and agent mention chips remain yellow with near-black readable text, including on hover. ## Screenshots Screenshots are posted in the PR discussion using immutable repository-hosted image URLs. Signed-off-by: tulsi <[email protected]>
1 parent 2f13e30 commit 0e69b3f

7 files changed

Lines changed: 149 additions & 24 deletions

File tree

‎desktop/src/features/channels/useUnreadChannels.ts‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -784,13 +784,8 @@ export function useUnreadChannels(
784784
relayClient,
785785
]);
786786

787-
// Unread = inactive channels, plus any channel manually marked unread this
788-
// session. A manually marked active channel must remain visible as unread
789-
// until the user explicitly marks it read again.
790-
// High-priority unread = DMs or channels with a mention/broadcast newer
791-
// than the read marker. Forced-unread channels are dot tier only (not
792-
// high-priority). Both sets share identical deps and always invalidate
793-
// together, so they are computed in a single memo.
787+
// Derive unread and high-priority projections together so they invalidate
788+
// from the same read-state snapshot.
794789
const rawUnread =
795790
// biome-ignore lint/correctness/useExhaustiveDependencies: readStateVersion and latestVersion are intentional invalidation signals
796791
React.useMemo(() => {
@@ -841,7 +836,7 @@ export function useUnreadChannels(
841836
if (!isForcedUnread) continue;
842837
unread.add(channel.id);
843838
topLevelUnread.add(channel.id);
844-
counts.set(channel.id, 1);
839+
if (channel.channelType === "dm") counts.set(channel.id, 1);
845840
unreadChannelNotificationCount += 1;
846841
continue;
847842
}
@@ -863,13 +858,17 @@ export function useUnreadChannels(
863858
observedEvents,
864859
readAtForObservedEvent,
865860
);
866-
counts.set(channel.id, badgeCount);
867-
unreadChannelNotificationCount +=
861+
const appBadgeCount =
868862
nativeProjection?.appBadgeCount ??
869863
countUnreadAppBadgeObservedEvents(
870864
observedEvents,
871865
readAtForObservedEvent,
872866
);
867+
counts.set(
868+
channel.id,
869+
channel.channelType === "dm" ? badgeCount : appBadgeCount,
870+
);
871+
unreadChannelNotificationCount += appBadgeCount;
873872

874873
// DM channels: any unread DM is high-priority.
875874
if (channel.channelType === "dm") {

‎desktop/src/features/sidebar/ui/SidebarSection.tsx‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ function UnreadCountBadge({
7979
data-testid={`channel-unread-${channelName}`}
8080
>
8181
{formatUnreadCount(count)}
82-
<span className="sr-only"> new comment{count === 1 ? "" : "s"}</span>
82+
<span className="sr-only">
83+
{" "}
84+
unread notification{count === 1 ? "" : "s"}
85+
</span>
8386
</span>
8487
);
8588
}
@@ -255,6 +258,7 @@ export function ChannelMenuButton({
255258
label,
256259
isActive,
257260
hasUnread,
261+
unreadCount = 0,
258262
activeWorking,
259263
isMuted,
260264
dmParticipants,
@@ -354,7 +358,13 @@ export function ChannelMenuButton({
354358
)}
355359
/>
356360
) : null}
357-
{hasThreadUnread ? (
361+
{!isActive && channel.channelType !== "dm" && unreadCount > 0 ? (
362+
<UnreadCountBadge
363+
channelName={channel.name}
364+
className="ml-auto bg-notification text-notification-foreground"
365+
count={unreadCount}
366+
/>
367+
) : hasThreadUnread ? (
358368
<UnreadDotBadge channelName={channel.name} className="ml-auto" />
359369
) : null}
360370
</SidebarMenuButton>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,21 @@
302302
color: hsl(var(--primary) / 0.9);
303303
}
304304

305+
/* @mentions use an opaque highlighter-yellow treatment so they scan
306+
differently from channel links while retaining AA contrast on every theme.
307+
Shared by human and agent chips in both timeline and composer. */
308+
.message-markdown .mention-chip.inline-chip-icon-human,
309+
.message-markdown .mention-chip.inline-chip-icon-agent {
310+
background: hsl(var(--mention-highlight));
311+
color: hsl(var(--buzz-content-dark));
312+
}
313+
314+
.message-markdown .mention-chip-hover.inline-chip-icon-human:hover,
315+
.message-markdown .mention-chip-hover.inline-chip-icon-agent:hover {
316+
background: hsl(var(--mention-highlight-hover));
317+
color: hsl(var(--buzz-content-dark));
318+
}
319+
305320
.message-markdown .mention-prefix-hidden {
306321
display: inline-block;
307322
width: 0;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
--accent-foreground: 234 16.02% 35.49%;
2929
--destructive: 347 86.67% 44.12%;
3030
--destructive-foreground: 220 23.08% 94.9%;
31+
/* Notification attention colors are fixed across syntax themes. Unlike
32+
destructive, these must stay recognizably red with AA label contrast. */
33+
--notification: 348 65% 48%;
34+
--notification-foreground: 350 100% 98%;
35+
/* Opaque highlighter colors keep near-black mention text readable on every
36+
message surface instead of depending on the active theme underneath. */
37+
--mention-highlight: 48 96% 70%;
38+
--mention-highlight-hover: 48 96% 62%;
3139
--border: 225 13.56% 76.86%;
3240
--input: 225 13.56% 76.86%;
3341
--ring: 234 16.02% 35.49%;

‎desktop/tailwind.config.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ export default {
110110
DEFAULT: "hsl(var(--destructive))",
111111
foreground: "hsl(var(--destructive-foreground))",
112112
},
113+
notification: {
114+
DEFAULT: "hsl(var(--notification))",
115+
foreground: "hsl(var(--notification-foreground))",
116+
},
113117
border: "hsl(var(--border))",
114118
input: "hsl(var(--input))",
115119
ring: "hsl(var(--ring))",

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

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,14 @@ test("regular message bolds inactive channel without numeric badge", async ({
402402
);
403403
});
404404

405-
test("top-level @mention bolds the channel without a row badge", async ({
405+
test("top-level @mention shows a red numeric badge on its channel", async ({
406406
page,
407407
}) => {
408+
// slack-ochin maps the generic destructive pair to white-on-white. The
409+
// notification pair must remain independently red and readable.
410+
await page.addInitScript(() => {
411+
window.localStorage.setItem("buzz-theme", "slack-ochin");
412+
});
408413
await page.goto("/");
409414
await page.getByTestId("channel-general").click();
410415
await expect(page.getByTestId("chat-title")).toHaveText("general");
@@ -413,13 +418,18 @@ test("top-level @mention bolds the channel without a row badge", async ({
413418

414419
await page.evaluate(
415420
({ pubkey, mentionPubkey }) => {
416-
window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
417-
channelName: "random",
418-
content: "Hey @tyler check this out",
419-
kind: 40002,
420-
pubkey,
421-
mentionPubkeys: [mentionPubkey],
422-
});
421+
for (const content of [
422+
"Hey @tyler check this out",
423+
"One more for @tyler",
424+
]) {
425+
window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
426+
channelName: "random",
427+
content,
428+
kind: 40002,
429+
pubkey,
430+
mentionPubkeys: [mentionPubkey],
431+
});
432+
}
423433
},
424434
{
425435
pubkey: TEST_IDENTITIES.alice.pubkey,
@@ -431,9 +441,38 @@ test("top-level @mention bolds the channel without a row badge", async ({
431441
"font-weight",
432442
"700",
433443
);
434-
await expect(page.getByTestId("channel-unread-random")).toHaveCount(0);
444+
const mentionBadge = page.getByTestId("channel-unread-random");
445+
await expect(mentionBadge).toHaveText("2 unread notifications");
446+
await expect(mentionBadge).toHaveClass(/bg-notification/);
447+
await expect(mentionBadge).toHaveCSS("background-color", "rgb(202, 43, 75)");
448+
await expect(mentionBadge).toHaveCSS("color", "rgb(255, 245, 247)");
449+
const badgeContrast = await mentionBadge.evaluate((element) => {
450+
const parseRgb = (value: string) =>
451+
(value.match(/[\d.]+/g) ?? []).slice(0, 3).map(Number);
452+
const luminance = (color: number[]) =>
453+
color
454+
.map((channel) => {
455+
const value = channel / 255;
456+
return value <= 0.04045
457+
? value / 12.92
458+
: ((value + 0.055) / 1.055) ** 2.4;
459+
})
460+
.reduce(
461+
(sum, channel, index) =>
462+
sum + channel * [0.2126, 0.7152, 0.0722][index],
463+
0,
464+
);
465+
const style = getComputedStyle(element);
466+
const foreground = luminance(parseRgb(style.color));
467+
const background = luminance(parseRgb(style.backgroundColor));
468+
return (
469+
(Math.max(foreground, background) + 0.05) /
470+
(Math.min(foreground, background) + 0.05)
471+
);
472+
});
473+
expect(badgeContrast).toBeGreaterThanOrEqual(4.5);
435474
await expect(page.getByTestId("channel-unread-dot-random")).toHaveCount(0);
436-
await waitForBadgeState(page, withAdditionalBadgeCount(baselineBadge, 1));
475+
await waitForBadgeState(page, withAdditionalBadgeCount(baselineBadge, 2));
437476
});
438477

439478
test("numeric badge increments for DM message", async ({ page }) => {
@@ -496,7 +535,7 @@ test("interested thread reply shows the channel preview dot without incrementing
496535
await waitForBadgeState(page, baselineBadge);
497536
});
498537

499-
test("broadcast reply bolds the channel without a thread dot", async ({
538+
test("broadcast reply shows a numeric channel badge without a thread dot", async ({
500539
page,
501540
}) => {
502541
await page.goto("/");
@@ -525,7 +564,9 @@ test("broadcast reply bolds the channel without a thread dot", async ({
525564
"font-weight",
526565
"700",
527566
);
528-
await expect(page.getByTestId("channel-unread-random")).toHaveCount(0);
567+
await expect(page.getByTestId("channel-unread-random")).toHaveText(
568+
"1 unread notification",
569+
);
529570
await expect(page.getByTestId("channel-unread-dot-random")).toHaveCount(0);
530571
await waitForBadgeState(page, withAdditionalBadgeCount(baselineBadge, 1));
531572
});

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,37 @@ const DM_THREAD_AGENT_MENTION_ERROR_TEXT =
3737
const DM_THREAD_MEMBERS_LOADING_ERROR_TEXT =
3838
"Checking conversation members. Try again in a moment.";
3939

40+
async function expectTextContrast(
41+
locator: import("@playwright/test").Locator,
42+
minimum = 4.5,
43+
) {
44+
const contrastRatio = await locator.evaluate((element) => {
45+
const parseRgb = (value: string) =>
46+
(value.match(/[\d.]+/g) ?? []).slice(0, 3).map(Number);
47+
const luminance = (color: number[]) =>
48+
color
49+
.map((channel) => {
50+
const value = channel / 255;
51+
return value <= 0.04045
52+
? value / 12.92
53+
: ((value + 0.055) / 1.055) ** 2.4;
54+
})
55+
.reduce(
56+
(sum, channel, index) =>
57+
sum + channel * [0.2126, 0.7152, 0.0722][index],
58+
0,
59+
);
60+
const style = getComputedStyle(element);
61+
const foreground = luminance(parseRgb(style.color));
62+
const background = luminance(parseRgb(style.backgroundColor));
63+
return (
64+
(Math.max(foreground, background) + 0.05) /
65+
(Math.min(foreground, background) + 0.05)
66+
);
67+
});
68+
expect(contrastRatio).toBeGreaterThanOrEqual(minimum);
69+
}
70+
4071
/** Locator scoped to the mention autocomplete dropdown inside the composer. */
4172
function autocomplete(page: import("@playwright/test").Page) {
4273
return page
@@ -2598,6 +2629,9 @@ test("sent non-member person mention uses the normal mention style", async ({
25982629
test("sent managed non-member agent mention uses the agent mention style", async ({
25992630
page,
26002631
}) => {
2632+
await page.addInitScript(() => {
2633+
window.localStorage.setItem("buzz-theme", "buzz-dark");
2634+
});
26012635
await installMockBridge(page, {
26022636
managedAgents: [
26032637
{
@@ -2627,6 +2661,13 @@ test("sent managed non-member agent mention uses the agent mention style", async
26272661
await expect(mentionChip).toBeVisible();
26282662
await expect(mentionChip).toHaveText("charlie");
26292663
await expect(mentionChip).toHaveClass(/agent-mention-highlight/);
2664+
await expect(mentionChip).toHaveCSS("background-color", "rgb(252, 223, 105)");
2665+
await expect(mentionChip).toHaveCSS("color", "rgb(26, 26, 26)");
2666+
await expectTextContrast(mentionChip);
2667+
await mentionChip.hover();
2668+
await expect(mentionChip).toHaveCSS("background-color", "rgb(251, 214, 65)");
2669+
await expect(mentionChip).toHaveCSS("color", "rgb(26, 26, 26)");
2670+
await expectTextContrast(mentionChip);
26302671
});
26312672

26322673
test("mention button opens autocomplete and inserts a selected member", async ({
@@ -2732,6 +2773,13 @@ test("mention text is highlighted in sent messages", async ({ page }) => {
27322773
await expect(mentionChip).toBeVisible();
27332774
await expect(mentionChip).toHaveText("bob");
27342775
await expect(mentionChip).toHaveClass(/inline-chip-icon-human/);
2776+
await expect(mentionChip).toHaveCSS("background-color", "rgb(252, 223, 105)");
2777+
await expect(mentionChip).toHaveCSS("color", "rgb(26, 26, 26)");
2778+
await expectTextContrast(mentionChip);
2779+
await mentionChip.hover();
2780+
await expect(mentionChip).toHaveCSS("background-color", "rgb(251, 214, 65)");
2781+
await expect(mentionChip).toHaveCSS("color", "rgb(26, 26, 26)");
2782+
await expectTextContrast(mentionChip);
27352783
});
27362784

27372785
test("clicking author name opens user profile panel", async ({ page }) => {

0 commit comments

Comments
 (0)