this.roomList = roomList;
this.roomIdToNoti = new Map();
+ this.roomIdToPopupNotis = new Map();
+ this.eventIdToPopupNoti = new Map();
// this._initNoti();
this._listenEvents();
const noti = new window.Notification(title, {
body: mEvent.getContent().body,
icon,
+ tag: mEvent.getId(),
silent: settings.isNotificationSounds,
});
if (settings.isNotificationSounds) {
noti.onshow = () => this._playNotiSound();
}
noti.onclick = () => selectRoom(room.roomId, mEvent.getId());
+
+ this.eventIdToPopupNoti.set(mEvent.getId(), noti);
+ if (this.roomIdToPopupNotis.has(room.roomId)) {
+ this.roomIdToPopupNotis.get(room.roomId).push(noti);
+ } else {
+ this.roomIdToPopupNotis.set(room.roomId, [noti]);
+ }
} else {
this._playNotiSound();
}
}
+ _deletePopupNoti(eventId) {
+ this.eventIdToPopupNoti.get(eventId)?.close();
+ this.eventIdToPopupNoti.delete(eventId);
+ }
+
+ _deletePopupRoomNotis(roomId) {
+ this.roomIdToPopupNotis.get(roomId)?.forEach((n) => {
+ this.eventIdToPopupNoti.delete(n.tag);
+ n.close();
+ });
+ this.roomIdToPopupNotis.delete(roomId);
+ }
+
_playNotiSound() {
if (!this._notiAudio) {
this._notiAudio = document.getElementById('notificationSound');
_listenEvents() {
this.matrixClient.on('Room.timeline', (mEvent, room) => {
+ if (mEvent.isRedaction()) this._deletePopupNoti(mEvent.event.redacts);
+
if (room.isSpaceRoom()) return;
if (!isNotifEvent(mEvent)) return;
if (readerUserId !== this.matrixClient.getUserId()) return;
this.deleteNoti(room.roomId);
+
+ this._deletePopupRoomNotis(room.roomId);
}
});