From b15db203470d42f04357117e1143af4f1796abe8 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 19 Oct 2024 21:09:55 +0300 Subject: [PATCH] web/notifications: close notification when room is read from another client --- web/src/api/statestore/main.ts | 2 ++ web/src/api/statestore/room.ts | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/web/src/api/statestore/main.ts b/web/src/api/statestore/main.ts index 7bb1185..157daa8 100644 --- a/web/src/api/statestore/main.ts +++ b/web/src/api/statestore/main.ts @@ -158,6 +158,8 @@ export class StateStore { // image: ..., tag: rowid.toString(), }) + room.openNotifications.set(rowid, notif) + notif.onclose = () => room.openNotifications.delete(rowid) notif.onclick = () => this.onClickNotification(room.roomID) if (sound) { // TODO play sound diff --git a/web/src/api/statestore/room.ts b/web/src/api/statestore/room.ts index fd5333b..77b1d34 100644 --- a/web/src/api/statestore/room.ts +++ b/web/src/api/statestore/room.ts @@ -76,6 +76,7 @@ export class RoomStateStore { readonly eventsByID: Map = new Map() readonly timelineSub = new Subscribable() readonly eventSubs: Map = new Map() + readonly openNotifications: Map = new Map() readonly pendingEvents: EventRowID[] = [] paginating = false paginationRequestedForRow = -1 @@ -203,6 +204,12 @@ export class RoomStateStore { } else { this.timeline.push(...sync.timeline) } + if (sync.meta.unread_notifications === 0 && sync.meta.unread_highlights === 0) { + for (const notif of this.openNotifications.values()) { + notif.close() + } + this.openNotifications.clear() + } this.notifyTimelineSubscribers() }