Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit bb8348c

Browse files
committed
Add a badge to the threads icon if any threads are unread.
1 parent 712ca60 commit bb8348c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/components/views/right_panel/RoomHeaderButtons.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { NotificationStateEvents } from "../../../stores/notifications/Notificat
4444
import PosthogTrackers from "../../../PosthogTrackers";
4545
import { ButtonEvent } from "../elements/AccessibleButton";
4646
import { MatrixClientPeg } from "../../../MatrixClientPeg";
47+
import { doesRoomOrThreadHaveUnreadMessages } from "../../../Unread";
4748

4849
const ROOM_INFO_PHASES = [
4950
RightPanelPhases.RoomSummary,
@@ -191,9 +192,17 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
191192
return NotificationColor.Red;
192193
case NotificationCountType.Total:
193194
return NotificationColor.Grey;
194-
default:
195-
return NotificationColor.None;
196195
}
196+
// We don't have any notified messages, but we might have unread messages. Let's
197+
// find out.
198+
for (const thread of this.props.room!.getThreads()) {
199+
// If the current thread has unread messages, we're done.
200+
if (doesRoomOrThreadHaveUnreadMessages(thread)) {
201+
return NotificationColor.Bold;
202+
}
203+
}
204+
// Otherwise, no notification color.
205+
return NotificationColor.None;
197206
}
198207

199208
private onUpdateStatus = (notificationState: SummarizedNotificationState): void => {

test/components/views/right_panel/RoomHeaderButtons-test.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import RoomHeaderButtons from "../../../../src/components/views/right_panel/Room
2424
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
2525
import SettingsStore from "../../../../src/settings/SettingsStore";
2626
import { stubClient } from "../../../test-utils";
27+
import { mkThread } from "../../../test-utils/threads";
2728

2829
describe("RoomHeaderButtons-test.tsx", function () {
2930
const ROOM_ID = "!roomId:example.org";
@@ -52,7 +53,7 @@ describe("RoomHeaderButtons-test.tsx", function () {
5253
return container.querySelector(".mx_RightPanel_threadsButton");
5354
}
5455

55-
function isIndicatorOfType(container, type: "red" | "gray") {
56+
function isIndicatorOfType(container, type: "red" | "gray" | "bold") {
5657
return container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator").className.includes(type);
5758
}
5859

@@ -76,7 +77,7 @@ describe("RoomHeaderButtons-test.tsx", function () {
7677
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
7778
});
7879

79-
it("room wide notification does not change the thread button", () => {
80+
it("thread notification does change the thread button", () => {
8081
const { container } = getComponent(room);
8182

8283
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Total, 1);
@@ -89,6 +90,10 @@ describe("RoomHeaderButtons-test.tsx", function () {
8990
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Highlight, 0);
9091

9192
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
93+
94+
// Thread activity should appear on the icon.
95+
mkThread({ room, client, authorId: client.getUserId()!, participantUserIds: ["@alice:example.org"] });
96+
expect(isIndicatorOfType(getComponent(room), "bold")).toBe(true);
9297
});
9398

9499
it("does not explode without a room", () => {

0 commit comments

Comments
 (0)