From e907d4978d52b701acdd31e3f245e4cb42e83ade Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 23 Feb 2026 17:40:38 +0000 Subject: [PATCH] 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> --- src/BasePlatform.ts | 8 -------- src/Notifier.ts | 4 +--- test/unit-tests/Notifier-test.ts | 19 +++++++++++++++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/BasePlatform.ts b/src/BasePlatform.ts index 5c81beb9ff..822b282e25 100644 --- a/src/BasePlatform.ts +++ b/src/BasePlatform.ts @@ -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 diff --git a/src/Notifier.ts b/src/Notifier.ts index 6f7922fb94..dbe890909e 100644 --- a/src/Notifier.ts +++ b/src/Notifier.ts @@ -433,11 +433,9 @@ class NotifierClass extends TypedEventEmitter { 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);