From 64670732b061e1b817be3100898129828997e1ce Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Wed, 16 Mar 2022 18:44:42 +0530 Subject: [PATCH] Fix sending message not mark as read Signed-off-by: Ajay Bura --- src/client/state/RoomTimeline.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/client/state/RoomTimeline.js b/src/client/state/RoomTimeline.js index c0895b08..bccb197d 100644 --- a/src/client/state/RoomTimeline.js +++ b/src/client/state/RoomTimeline.js @@ -230,10 +230,18 @@ class RoomTimeline extends EventEmitter { markAllAsRead() { const readEventId = this.getReadUpToEventId(); + const getLatestValidEvent = () => { + for (let i = this.timeline.length - 1; i >= 0; i -= 1) { + const latestEvent = this.timeline[i]; + if (latestEvent.getId() === readEventId) return null; + if (!latestEvent.isSending()) return latestEvent; + } + return null; + }; this.notifications.deleteNoti(this.roomId); if (this.timeline.length === 0) return; - const latestEvent = this.timeline[this.timeline.length - 1]; - if (latestEvent.isSending() || latestEvent.getId().startsWith('~')) return; + const latestEvent = getLatestValidEvent(); + if (latestEvent === null) return; if (readEventId === latestEvent.getId()) return; this.matrixClient.sendReadReceipt(latestEvent); this.emit(cons.events.roomTimeline.MARKED_AS_READ, latestEvent);