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

Commit 3a50100

Browse files
author
Germain
authored
Add setting to hide bold notifications (#9705)
1 parent 474f464 commit 3a50100

File tree

12 files changed

+65
-13
lines changed

12 files changed

+65
-13
lines changed

src/components/views/rooms/NotificationBadge/StatelessNotificationBadge.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import classNames from "classnames";
2020
import { formatCount } from "../../../../utils/FormattingUtils";
2121
import AccessibleButton from "../../elements/AccessibleButton";
2222
import { NotificationColor } from "../../../../stores/notifications/NotificationColor";
23+
import { useSettingValue } from "../../../../hooks/useSettings";
2324

2425
interface Props {
2526
symbol: string | null;
@@ -37,8 +38,12 @@ export function StatelessNotificationBadge({
3738
count,
3839
color,
3940
...props }: Props) {
41+
const hideBold = useSettingValue("feature_hidebold");
42+
4043
// Don't show a badge if we don't need to
41-
if (color === NotificationColor.None) return null;
44+
if (color === NotificationColor.None || (hideBold && color == NotificationColor.Bold)) {
45+
return null;
46+
}
4247

4348
const hasUnreadCount = color >= NotificationColor.Grey && (!!count || !!symbol);
4449

src/i18n/strings/en_EN.json

+1
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@
960960
"Show stickers button": "Show stickers button",
961961
"Show polls button": "Show polls button",
962962
"Insert a trailing colon after user mentions at the start of a message": "Insert a trailing colon after user mentions at the start of a message",
963+
"Hide notification dot (only display counters badges)": "Hide notification dot (only display counters badges)",
963964
"Use a more compact 'Modern' layout": "Use a more compact 'Modern' layout",
964965
"Show a placeholder for removed messages": "Show a placeholder for removed messages",
965966
"Show join/leave messages (invites/removes/bans unaffected)": "Show join/leave messages (invites/removes/bans unaffected)",

src/settings/Settings.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,18 @@ export const SETTINGS: {[setting: string]: ISetting} = {
556556
supportedLevels: LEVELS_ROOM_OR_ACCOUNT,
557557
default: false,
558558
},
559+
"feature_hidebold": {
560+
isFeature: true,
561+
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
562+
displayName: _td("Hide notification dot (only display counters badges)"),
563+
labsGroup: LabGroup.Rooms,
564+
default: false,
565+
},
559566
"useCompactLayout": {
560567
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
561568
displayName: _td("Use a more compact 'Modern' layout"),
562569
default: false,
563-
controller: new IncompatibleController("layout", false, v => v !== Layout.Group),
570+
controller: new IncompatibleController("layout", false, (v: Layout) => v !== Layout.Group),
564571
},
565572
"showRedactions": {
566573
supportedLevels: LEVELS_ROOM_SETTINGS_WITH_ROOM,

src/stores/notifications/ListNotificationState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ListNotificationState extends NotificationState {
3131
super();
3232
}
3333

34-
public get symbol(): string {
34+
public get symbol(): string | null {
3535
return this._color === NotificationColor.Unsent ? "!" : null;
3636
}
3737

src/stores/notifications/NotificationState.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { TypedEventEmitter } from "matrix-js-sdk/src/models/typed-event-emitter"
1818

1919
import { NotificationColor } from "./NotificationColor";
2020
import { IDestroyable } from "../../utils/IDestroyable";
21+
import SettingsStore from "../../settings/SettingsStore";
2122

2223
export interface INotificationStateSnapshotParams {
2324
symbol: string | null;
@@ -37,11 +38,22 @@ export abstract class NotificationState
3738
extends TypedEventEmitter<NotificationStateEvents, EventHandlerMap>
3839
implements INotificationStateSnapshotParams, IDestroyable {
3940
//
40-
protected _symbol: string | null;
41-
protected _count: number;
42-
protected _color: NotificationColor;
41+
protected _symbol: string | null = null;
42+
protected _count = 0;
43+
protected _color: NotificationColor = NotificationColor.None;
44+
45+
private watcherReferences: string[] = [];
46+
47+
constructor() {
48+
super();
49+
this.watcherReferences.push(
50+
SettingsStore.watchSetting("feature_hidebold", null, () => {
51+
this.emit(NotificationStateEvents.Update);
52+
}),
53+
);
54+
}
4355

44-
public get symbol(): string {
56+
public get symbol(): string | null {
4557
return this._symbol;
4658
}
4759

@@ -58,7 +70,12 @@ export abstract class NotificationState
5870
}
5971

6072
public get isUnread(): boolean {
61-
return this.color >= NotificationColor.Bold;
73+
if (this.color > NotificationColor.Bold) {
74+
return true;
75+
} else {
76+
const hideBold = SettingsStore.getValue("feature_hidebold");
77+
return this.color === NotificationColor.Bold && !hideBold;
78+
}
6279
}
6380

6481
public get hasUnreadCount(): boolean {
@@ -81,11 +98,15 @@ export abstract class NotificationState
8198

8299
public destroy(): void {
83100
this.removeAllListeners(NotificationStateEvents.Update);
101+
for (const watcherReference of this.watcherReferences) {
102+
SettingsStore.unwatchSetting(watcherReference);
103+
}
104+
this.watcherReferences = [];
84105
}
85106
}
86107

87108
export class NotificationStateSnapshot {
88-
private readonly symbol: string;
109+
private readonly symbol: string | null;
89110
private readonly count: number;
90111
private readonly color: NotificationColor;
91112

src/stores/notifications/RoomNotificationState.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export class RoomNotificationState extends NotificationState implements IDestroy
9898
this.updateNotificationState();
9999
};
100100

101-
private handleRoomEventUpdate = (event: MatrixEvent, room: Room | null) => {
102-
if (room?.roomId !== this.room.roomId) return; // ignore - not for us or notifications timeline
101+
private handleRoomEventUpdate = (event: MatrixEvent) => {
102+
if (event?.getRoomId() !== this.room.roomId) return; // ignore - not for us or notifications timeline
103103
this.updateNotificationState();
104104
};
105105

src/stores/notifications/SpaceNotificationState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class SpaceNotificationState extends NotificationState {
3232
super();
3333
}
3434

35-
public get symbol(): string {
35+
public get symbol(): string | null {
3636
return this._color === NotificationColor.Unsent ? "!" : null;
3737
}
3838

src/stores/notifications/StaticNotificationState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { NotificationState } from "./NotificationState";
2020
export class StaticNotificationState extends NotificationState {
2121
public static readonly RED_EXCLAMATION = StaticNotificationState.forSymbol("!", NotificationColor.Red);
2222

23-
constructor(symbol: string, count: number, color: NotificationColor) {
23+
constructor(symbol: string | null, count: number, color: NotificationColor) {
2424
super();
2525
this._symbol = symbol;
2626
this._count = count;

test/components/views/rooms/NotificationBadge/NotificationBadge-test.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import React from "react";
2020
import {
2121
StatelessNotificationBadge,
2222
} from "../../../../../src/components/views/rooms/NotificationBadge/StatelessNotificationBadge";
23+
import SettingsStore from "../../../../../src/settings/SettingsStore";
2324
import { NotificationColor } from "../../../../../src/stores/notifications/NotificationColor";
2425

2526
describe("NotificationBadge", () => {
@@ -45,5 +46,19 @@ describe("NotificationBadge", () => {
4546
fireEvent.mouseLeave(container.firstChild);
4647
expect(cb).toHaveBeenCalledTimes(3);
4748
});
49+
50+
it("hides the bold icon when the settings is set", () => {
51+
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
52+
return name === "feature_hidebold";
53+
});
54+
55+
const { container } = render(<StatelessNotificationBadge
56+
symbol=""
57+
color={NotificationColor.Bold}
58+
count={1}
59+
/>);
60+
61+
expect(container.firstChild).toBeNull();
62+
});
4863
});
4964
});

test/components/views/spaces/QuickThemeSwitcher-test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jest.mock('../../../../src/settings/SettingsStore', () => ({
3838
setValue: jest.fn(),
3939
getValue: jest.fn(),
4040
monitorSetting: jest.fn(),
41+
watchSetting: jest.fn(),
4142
}));
4243

4344
jest.mock('../../../../src/dispatcher/dispatcher', () => ({

test/stores/TypingStore-test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { TestSdkContext } from "../TestSdkContext";
2525
jest.mock("../../src/settings/SettingsStore", () => ({
2626
getValue: jest.fn(),
2727
monitorSetting: jest.fn(),
28+
watchSetting: jest.fn(),
2829
}));
2930

3031
describe("TypingStore", () => {

test/utils/MultiInviter-test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jest.mock('../../src/Modal', () => ({
4242
jest.mock('../../src/settings/SettingsStore', () => ({
4343
getValue: jest.fn(),
4444
monitorSetting: jest.fn(),
45+
watchSetting: jest.fn(),
4546
}));
4647

4748
const mockPromptBeforeInviteUnknownUsers = (value: boolean) => {

0 commit comments

Comments
 (0)