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

Commit

Permalink
Show activity in the threads icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Dec 12, 2022
1 parent 9220a0c commit 73bb851
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/components/views/right_panel/RoomHeaderButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { NotificationStateEvents } from "../../../stores/notifications/Notificat
import PosthogTrackers from "../../../PosthogTrackers";
import { ButtonEvent } from "../elements/AccessibleButton";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { doesRoomOrThreadHaveUnreadMessages } from "../../../Unread";

const ROOM_INFO_PHASES = [
RightPanelPhases.RoomSummary,
Expand Down Expand Up @@ -192,9 +193,17 @@ export default class RoomHeaderButtons extends HeaderButtons<IProps> {
return NotificationColor.Red;
case NotificationCountType.Total:
return NotificationColor.Grey;
default:
return NotificationColor.None;
}
// We don't have any notified messages, but we might have unread messages. Let's
// find out.
for (const thread of this.props.room!.getThreads()) {
// If the current thread has unread messages, we're done.
if (doesRoomOrThreadHaveUnreadMessages(thread)) {
return NotificationColor.Bold;
}
}
// Otherwise, no notification color.
return NotificationColor.None;
}

private onUpdateStatus = (notificationState: SummarizedNotificationState): void => {
Expand Down
9 changes: 7 additions & 2 deletions test/components/views/right_panel/RoomHeaderButtons-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import RoomHeaderButtons from "../../../../src/components/views/right_panel/Room
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import SettingsStore from "../../../../src/settings/SettingsStore";
import { stubClient } from "../../../test-utils";
import { mkThread } from "../../../test-utils/threads";

describe("RoomHeaderButtons-test.tsx", function() {
const ROOM_ID = "!roomId:example.org";
Expand Down Expand Up @@ -55,7 +56,7 @@ describe("RoomHeaderButtons-test.tsx", function() {
return container.querySelector(".mx_RightPanel_threadsButton");
}

function isIndicatorOfType(container, type: "red" | "gray") {
function isIndicatorOfType(container, type: "red" | "gray" | "bold") {
return container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")
.className
.includes(type);
Expand All @@ -81,7 +82,7 @@ describe("RoomHeaderButtons-test.tsx", function() {
expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();
});

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

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

expect(container.querySelector(".mx_RightPanel_threadsButton .mx_Indicator")).toBeNull();

// Thread activity should appear on the icon.
mkThread({ room, client, authorId: client.getUserId()!, participantUserIds: ["@alice:example.org"] });
expect(isIndicatorOfType(getComponent(room), "bold")).toBe(true);
});

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

0 comments on commit 73bb851

Please sign in to comment.