web/notifications: close notification when room is read from another client

This commit is contained in:
Tulir Asokan 2024-10-19 21:09:55 +03:00
parent 7676f21292
commit b15db20347
2 changed files with 9 additions and 0 deletions

View file

@ -158,6 +158,8 @@ export class StateStore {
// image: ..., // image: ...,
tag: rowid.toString(), tag: rowid.toString(),
}) })
room.openNotifications.set(rowid, notif)
notif.onclose = () => room.openNotifications.delete(rowid)
notif.onclick = () => this.onClickNotification(room.roomID) notif.onclick = () => this.onClickNotification(room.roomID)
if (sound) { if (sound) {
// TODO play sound // TODO play sound

View file

@ -76,6 +76,7 @@ export class RoomStateStore {
readonly eventsByID: Map<EventID, MemDBEvent> = new Map() readonly eventsByID: Map<EventID, MemDBEvent> = new Map()
readonly timelineSub = new Subscribable() readonly timelineSub = new Subscribable()
readonly eventSubs: Map<EventID, EventSubscribable> = new Map() readonly eventSubs: Map<EventID, EventSubscribable> = new Map()
readonly openNotifications: Map<EventRowID, Notification> = new Map()
readonly pendingEvents: EventRowID[] = [] readonly pendingEvents: EventRowID[] = []
paginating = false paginating = false
paginationRequestedForRow = -1 paginationRequestedForRow = -1
@ -203,6 +204,12 @@ export class RoomStateStore {
} else { } else {
this.timeline.push(...sync.timeline) 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() this.notifyTimelineSubscribers()
} }