From 3c60976efa3ae0d4ab3e93a114cb00401b60e92b Mon Sep 17 00:00:00 2001 From: greentore <117551249+greentore@users.noreply.github.com> Date: Mon, 24 Jul 2023 06:40:43 +0200 Subject: [PATCH] Passive private receipt support (#1108) Co-authored-by: Ajay Bura <32841439+ajbura@users.noreply.github.com> --- src/client/state/Notifications.js | 22 ++++++++++++---------- src/client/state/cons.js | 4 ++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/client/state/Notifications.js b/src/client/state/Notifications.js index db4610a..13dd3e1 100644 --- a/src/client/state/Notifications.js +++ b/src/client/state/Notifications.js @@ -383,17 +383,19 @@ class Notifications extends EventEmitter { }); this.matrixClient.on('Room.receipt', (mEvent, room) => { - if (mEvent.getType() === 'm.receipt') { - if (room.isSpaceRoom()) return; - const content = mEvent.getContent(); - const readedEventId = Object.keys(content)[0]; - const readerUserId = Object.keys(content[readedEventId]['m.read'])[0]; - if (readerUserId !== this.matrixClient.getUserId()) return; + if (mEvent.getType() !== 'm.receipt' || room.isSpaceRoom()) return; + const content = mEvent.getContent(); + const userId = this.matrixClient.getUserId(); - this.deleteNoti(room.roomId); - - this._deletePopupRoomNotis(room.roomId); - } + Object.keys(content).forEach((eventId) => { + Object.entries(content[eventId]).forEach(([receiptType, receipt]) => { + if (!cons.supportReceiptTypes.includes(receiptType)) return; + if (Object.keys(receipt || {}).includes(userId)) { + this.deleteNoti(room.roomId); + this._deletePopupRoomNotis(room.roomId); + } + }); + }); }); this.matrixClient.on('Room.myMembership', (room, membership) => { diff --git a/src/client/state/cons.js b/src/client/state/cons.js index 8d9fda5..873c4e3 100644 --- a/src/client/state/cons.js +++ b/src/client/state/cons.js @@ -19,6 +19,10 @@ const cons = { 'm.room.member', 'm.sticker', ], + supportReceiptTypes: [ + 'm.read', + 'm.read.private', + ], notifs: { DEFAULT: 'default', ALL_MESSAGES: 'all_messages',