Threads notifications after app startup (#7253)
This commit is contained in:
parent
b4b81a455e
commit
38e5e94ee4
10 changed files with 194 additions and 28 deletions
|
@ -14,14 +14,23 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { EventEmitter } from "events";
|
||||
import { NotificationColor } from "./NotificationColor";
|
||||
import { IDestroyable } from "../../utils/IDestroyable";
|
||||
import { TypedEventEmitter } from "matrix-js-sdk/src/models/typed-event-emitter";
|
||||
|
||||
export const NOTIFICATION_STATE_UPDATE = "update";
|
||||
export interface INotificationStateSnapshotParams {
|
||||
symbol: string | null;
|
||||
count: number;
|
||||
color: NotificationColor;
|
||||
}
|
||||
|
||||
export abstract class NotificationState extends EventEmitter implements IDestroyable {
|
||||
protected _symbol: string;
|
||||
export enum NotificationStateEvents {
|
||||
Update = "update",
|
||||
}
|
||||
|
||||
export abstract class NotificationState extends TypedEventEmitter<NotificationStateEvents>
|
||||
implements INotificationStateSnapshotParams, IDestroyable {
|
||||
protected _symbol: string | null;
|
||||
protected _count: number;
|
||||
protected _color: NotificationColor;
|
||||
|
||||
|
@ -55,7 +64,7 @@ export abstract class NotificationState extends EventEmitter implements IDestroy
|
|||
|
||||
protected emitIfUpdated(snapshot: NotificationStateSnapshot) {
|
||||
if (snapshot.isDifferentFrom(this)) {
|
||||
this.emit(NOTIFICATION_STATE_UPDATE);
|
||||
this.emit(NotificationStateEvents.Update);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +73,7 @@ export abstract class NotificationState extends EventEmitter implements IDestroy
|
|||
}
|
||||
|
||||
public destroy(): void {
|
||||
this.removeAllListeners(NOTIFICATION_STATE_UPDATE);
|
||||
this.removeAllListeners(NotificationStateEvents.Update);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,13 +82,13 @@ export class NotificationStateSnapshot {
|
|||
private readonly count: number;
|
||||
private readonly color: NotificationColor;
|
||||
|
||||
constructor(state: NotificationState) {
|
||||
constructor(state: INotificationStateSnapshotParams) {
|
||||
this.symbol = state.symbol;
|
||||
this.count = state.count;
|
||||
this.color = state.color;
|
||||
}
|
||||
|
||||
public isDifferentFrom(other: NotificationState): boolean {
|
||||
public isDifferentFrom(other: INotificationStateSnapshotParams): boolean {
|
||||
const before = { count: this.count, symbol: this.symbol, color: this.color };
|
||||
const after = { count: other.count, symbol: other.symbol, color: other.color };
|
||||
return JSON.stringify(before) !== JSON.stringify(after);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue