Add setting to hide bold notifications (#9705)

This commit is contained in:
Germain
2022-12-06 09:59:17 +00:00
committed by GitHub
parent 474f464e48
commit 3a501003e2
12 changed files with 65 additions and 13 deletions
@@ -31,7 +31,7 @@ export class ListNotificationState extends NotificationState {
super();
}
public get symbol(): string {
public get symbol(): string | null {
return this._color === NotificationColor.Unsent ? "!" : null;
}
+27 -6
View File
@@ -18,6 +18,7 @@ import { TypedEventEmitter } from "matrix-js-sdk/src/models/typed-event-emitter"
import { NotificationColor } from "./NotificationColor";
import { IDestroyable } from "../../utils/IDestroyable";
import SettingsStore from "../../settings/SettingsStore";
export interface INotificationStateSnapshotParams {
symbol: string | null;
@@ -37,11 +38,22 @@ export abstract class NotificationState
extends TypedEventEmitter<NotificationStateEvents, EventHandlerMap>
implements INotificationStateSnapshotParams, IDestroyable {
//
protected _symbol: string | null;
protected _count: number;
protected _color: NotificationColor;
protected _symbol: string | null = null;
protected _count = 0;
protected _color: NotificationColor = NotificationColor.None;
public get symbol(): string {
private watcherReferences: string[] = [];
constructor() {
super();
this.watcherReferences.push(
SettingsStore.watchSetting("feature_hidebold", null, () => {
this.emit(NotificationStateEvents.Update);
}),
);
}
public get symbol(): string | null {
return this._symbol;
}
@@ -58,7 +70,12 @@ export abstract class NotificationState
}
public get isUnread(): boolean {
return this.color >= NotificationColor.Bold;
if (this.color > NotificationColor.Bold) {
return true;
} else {
const hideBold = SettingsStore.getValue("feature_hidebold");
return this.color === NotificationColor.Bold && !hideBold;
}
}
public get hasUnreadCount(): boolean {
@@ -81,11 +98,15 @@ export abstract class NotificationState
public destroy(): void {
this.removeAllListeners(NotificationStateEvents.Update);
for (const watcherReference of this.watcherReferences) {
SettingsStore.unwatchSetting(watcherReference);
}
this.watcherReferences = [];
}
}
export class NotificationStateSnapshot {
private readonly symbol: string;
private readonly symbol: string | null;
private readonly count: number;
private readonly color: NotificationColor;
@@ -98,8 +98,8 @@ export class RoomNotificationState extends NotificationState implements IDestroy
this.updateNotificationState();
};
private handleRoomEventUpdate = (event: MatrixEvent, room: Room | null) => {
if (room?.roomId !== this.room.roomId) return; // ignore - not for us or notifications timeline
private handleRoomEventUpdate = (event: MatrixEvent) => {
if (event?.getRoomId() !== this.room.roomId) return; // ignore - not for us or notifications timeline
this.updateNotificationState();
};
@@ -32,7 +32,7 @@ export class SpaceNotificationState extends NotificationState {
super();
}
public get symbol(): string {
public get symbol(): string | null {
return this._color === NotificationColor.Unsent ? "!" : null;
}
@@ -20,7 +20,7 @@ import { NotificationState } from "./NotificationState";
export class StaticNotificationState extends NotificationState {
public static readonly RED_EXCLAMATION = StaticNotificationState.forSymbol("!", NotificationColor.Red);
constructor(symbol: string, count: number, color: NotificationColor) {
constructor(symbol: string | null, count: number, color: NotificationColor) {
super();
this._symbol = symbol;
this._count = count;