Delete notifications after messages have been read or deleted (#830)
* Delete read notifications * Delete notifications for deleted messages * Correctly remove notification
This commit is contained in:
parent
a343d9999e
commit
b0174f3acc
1 changed files with 27 additions and 0 deletions
|
@ -43,6 +43,8 @@ class Notifications extends EventEmitter {
|
||||||
this.roomList = roomList;
|
this.roomList = roomList;
|
||||||
|
|
||||||
this.roomIdToNoti = new Map();
|
this.roomIdToNoti = new Map();
|
||||||
|
this.roomIdToPopupNotis = new Map();
|
||||||
|
this.eventIdToPopupNoti = new Map();
|
||||||
|
|
||||||
// this._initNoti();
|
// this._initNoti();
|
||||||
this._listenEvents();
|
this._listenEvents();
|
||||||
|
@ -258,17 +260,38 @@ class Notifications extends EventEmitter {
|
||||||
const noti = new window.Notification(title, {
|
const noti = new window.Notification(title, {
|
||||||
body: mEvent.getContent().body,
|
body: mEvent.getContent().body,
|
||||||
icon,
|
icon,
|
||||||
|
tag: mEvent.getId(),
|
||||||
silent: settings.isNotificationSounds,
|
silent: settings.isNotificationSounds,
|
||||||
});
|
});
|
||||||
if (settings.isNotificationSounds) {
|
if (settings.isNotificationSounds) {
|
||||||
noti.onshow = () => this._playNotiSound();
|
noti.onshow = () => this._playNotiSound();
|
||||||
}
|
}
|
||||||
noti.onclick = () => selectRoom(room.roomId, mEvent.getId());
|
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 {
|
} else {
|
||||||
this._playNotiSound();
|
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() {
|
_playNotiSound() {
|
||||||
if (!this._notiAudio) {
|
if (!this._notiAudio) {
|
||||||
this._notiAudio = document.getElementById('notificationSound');
|
this._notiAudio = document.getElementById('notificationSound');
|
||||||
|
@ -285,6 +308,8 @@ class Notifications extends EventEmitter {
|
||||||
|
|
||||||
_listenEvents() {
|
_listenEvents() {
|
||||||
this.matrixClient.on('Room.timeline', (mEvent, room) => {
|
this.matrixClient.on('Room.timeline', (mEvent, room) => {
|
||||||
|
if (mEvent.isRedaction()) this._deletePopupNoti(mEvent.event.redacts);
|
||||||
|
|
||||||
if (room.isSpaceRoom()) return;
|
if (room.isSpaceRoom()) return;
|
||||||
if (!isNotifEvent(mEvent)) return;
|
if (!isNotifEvent(mEvent)) return;
|
||||||
|
|
||||||
|
@ -355,6 +380,8 @@ class Notifications extends EventEmitter {
|
||||||
if (readerUserId !== this.matrixClient.getUserId()) return;
|
if (readerUserId !== this.matrixClient.getUserId()) return;
|
||||||
|
|
||||||
this.deleteNoti(room.roomId);
|
this.deleteNoti(room.roomId);
|
||||||
|
|
||||||
|
this._deletePopupRoomNotis(room.roomId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue