Previously we were creating a notification state whenever we needed one, which was leading to hundreds of listeners even on a small account. To ease the burden, and reduce the load of having to wake so many listeners, we now record a single listener for each tag ID and room combination. This commit also introduces a number of utilities to make future notification work a bit of an easier transition, such as the `isX` and `hasX` getters on the new NotificationState abstract class. Similarly, "snapshots" have been added to reduce code duplication between different kinds of states checking for updates. The ListNotificationState is now heavily tied into the store which offers it to help reuse the cache of room notification states. Fixes https://github.com/vector-im/riot-web/issues/14370
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
/*
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import { NotificationColor } from "./NotificationColor";
|
|
import { NotificationState } from "./NotificationState";
|
|
|
|
export class StaticNotificationState extends NotificationState {
|
|
constructor(symbol: string, count: number, color: NotificationColor) {
|
|
super();
|
|
this._symbol = symbol;
|
|
this._count = count;
|
|
this._color = color;
|
|
}
|
|
|
|
public static forCount(count: number, color: NotificationColor): StaticNotificationState {
|
|
return new StaticNotificationState(null, count, color);
|
|
}
|
|
|
|
public static forSymbol(symbol: string, color: NotificationColor): StaticNotificationState {
|
|
return new StaticNotificationState(symbol, 0, color);
|
|
}
|
|
}
|