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

Commit 73bb851

Browse files
committed
Show activity in the threads icon.
1 parent 9220a0c commit 73bb851

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,
@@ -192,9 +193,17 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
192193
return NotificationColor.Red;
193194
case NotificationCountType.Total:
194195
return NotificationColor.Grey;
195-
default:
196-
return NotificationColor.None;
197196
}
197+
// We don't have any notified messages, but we might have unread messages. Let's
198+
// find out.
199+
for (const thread of this.props.room!.getThreads()) {
200+
// If the current thread has unread messages, we're done.
201+
if (doesRoomOrThreadHaveUnreadMessages(thread)) {
202+
return NotificationColor.Bold;
203+
}
204+
}
205+
// Otherwise, no notification color.
206+
return NotificationColor.None;
198207
}
199208

200209
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";
@@ -55,7 +56,7 @@ describe("RoomHeaderButtons-test.tsx", function() {
5556
return container.querySelector(".mx_RightPanel_threadsButton");
5657
}
5758

58-
function isIndicatorOfType(container, type: "red" | "gray") {
59+
function isIndicatorOfType(container, type: "red" | "gray" | "bold") {
5960
return container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")
6061
.className
6162
.includes(type);
@@ -81,7 +82,7 @@ describe("RoomHeaderButtons-test.tsx", function() {
8182
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
8283
});
8384

84-
it("room wide notification does not change the thread button", () => {
85+
it.only("thread notification does change the thread button", () => {
8586
const { container } = getComponent(room);
8687

8788
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Total, 1);
@@ -94,6 +95,10 @@ describe("RoomHeaderButtons-test.tsx", function() {
9495
room.setThreadUnreadNotificationCount("$123", NotificationCountType.Highlight, 0);
9596

9697
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
98+
99+
// Thread activity should appear on the icon.
100+
mkThread({ room, client, authorId: client.getUserId()!, participantUserIds: ["@alice:example.org"] });
101+
expect(isIndicatorOfType(getComponent(room), "bold")).toBe(true);
97102
});
98103

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

0 commit comments

Comments
 (0)