mirror of
https://github.com/vector-im/element-web.git
synced 2026-03-02 03:52:20 +01:00
Simplify notifier-platform code for closing notifications (#32609)
* Simplify notifier-platform code for closing notifications Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
9c050c58b7
commit
e907d4978d
@ -245,14 +245,6 @@ export default abstract class BasePlatform {
|
||||
|
||||
public loudNotification(ev: MatrixEvent, room: Room): void {}
|
||||
|
||||
public clearNotification(notif: Notification): void {
|
||||
// Some browsers don't support this, e.g Safari on iOS
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Notification/close
|
||||
if (notif.close) {
|
||||
notif.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the platform requires URL previews in tooltips, otherwise false.
|
||||
* @returns {boolean} whether the platform requires URL previews in tooltips
|
||||
|
||||
@ -433,11 +433,9 @@ class NotifierClass extends TypedEventEmitter<keyof EmittedEvents, EmittedEvents
|
||||
// do this. Instead, clear all notifications for a room once
|
||||
// there are no notifs left in that room., which is not quite
|
||||
// as good but it's something.
|
||||
const plaf = PlatformPeg.get();
|
||||
if (!plaf) return;
|
||||
if (this.notifsByRoom[room.roomId] === undefined) return;
|
||||
for (const notif of this.notifsByRoom[room.roomId]) {
|
||||
plaf.clearNotification(notif);
|
||||
notif.close();
|
||||
}
|
||||
delete this.notifsByRoom[room.roomId];
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ describe("Notifier", () => {
|
||||
MockPlatform = mockPlatformPeg({
|
||||
supportsNotifications: jest.fn().mockReturnValue(true),
|
||||
maySendNotifications: jest.fn().mockReturnValue(true),
|
||||
displayNotification: jest.fn(),
|
||||
displayNotification: jest.fn().mockReturnValue({ close: jest.fn() }),
|
||||
loudNotification: jest.fn(),
|
||||
});
|
||||
|
||||
@ -171,7 +171,7 @@ describe("Notifier", () => {
|
||||
const event = new MatrixEvent({
|
||||
sender: "@alice:server.org",
|
||||
type: "m.room.message",
|
||||
room_id: "!room:server.org",
|
||||
room_id: roomId,
|
||||
content: {
|
||||
body: "hey",
|
||||
},
|
||||
@ -271,6 +271,21 @@ describe("Notifier", () => {
|
||||
expect(MockPlatform.displayNotification).toHaveBeenCalledWith(testRoom.name, "hey", null, testRoom, event);
|
||||
});
|
||||
|
||||
it("closes a desktop notification when room is marked read", () => {
|
||||
mockClient!.emit(ClientEvent.Sync, SyncState.Syncing, null);
|
||||
emitLiveEvent(event);
|
||||
|
||||
expect(MockPlatform.displayNotification).toHaveBeenCalledWith(testRoom.name, "hey", null, testRoom, event);
|
||||
mockClient!.emit(RoomEvent.Receipt, event, testRoom);
|
||||
expect(
|
||||
(
|
||||
MockPlatform.displayNotification.mock.results[0].value as ReturnType<
|
||||
typeof MockPlatform.displayNotification
|
||||
>
|
||||
).close,
|
||||
).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("creates a loud notification when enabled", () => {
|
||||
mockClient!.emit(ClientEvent.Sync, SyncState.Syncing, null);
|
||||
emitLiveEvent(event);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user