From 9c12e113756e96edd2fa9ed0a196b3176268a783 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Fri, 17 Dec 2021 17:22:38 +0530 Subject: [PATCH] Fix read receipt count Signed-off-by: Ajay Bura --- src/app/molecules/message/Message.jsx | 2 +- src/client/state/RoomTimeline.js | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/app/molecules/message/Message.jsx b/src/app/molecules/message/Message.jsx index b376b7f..ad7038e 100644 --- a/src/app/molecules/message/Message.jsx +++ b/src/app/molecules/message/Message.jsx @@ -438,7 +438,7 @@ const MessageOptions = React.memo(({ Options openReadReceipts(roomId, roomTimeline.getEventReaders(eventId))} + onClick={() => openReadReceipts(roomId, roomTimeline.getEventReaders(mEvent))} > Read receipts diff --git a/src/client/state/RoomTimeline.js b/src/client/state/RoomTimeline.js index 014b63d..1a988d6 100644 --- a/src/client/state/RoomTimeline.js +++ b/src/client/state/RoomTimeline.js @@ -247,23 +247,26 @@ class RoomTimeline extends EventEmitter { getLiveReaders() { const lastEvent = this.timeline[this.timeline.length - 1]; const liveEvents = this.liveTimeline.getEvents(); - const lastLiveEvent = liveEvents[liveEvents.length - 1]; - let readers = []; - if (lastEvent) readers = this.room.getUsersReadUpTo(lastEvent); - if (lastLiveEvent !== lastEvent) { - readers.splice(readers.length, 0, ...this.room.getUsersReadUpTo(lastLiveEvent)); + const readers = []; + + for (let i = liveEvents.length - 1; i >= 0; i -= 1) { + readers.splice(readers.length, 0, ...this.room.getUsersReadUpTo(liveEvents[i])); + if (lastEvent === liveEvents[i]) break; } + return [...new Set(readers)]; } - getEventReaders(eventId) { + getEventReaders(mEvent) { + const liveEvents = this.liveTimeline.getEvents(); const readers = []; - let eventIndex = this.getEventIndex(eventId); - if (eventIndex < 0) return this.getLiveReaders(); - for (; eventIndex < this.timeline.length; eventIndex += 1) { - readers.splice(readers.length, 0, ...this.room.getUsersReadUpTo(this.timeline[eventIndex])); + + for (let i = liveEvents.length - 1; i >= 0; i -= 1) { + readers.splice(readers.length, 0, ...this.room.getUsersReadUpTo(liveEvents[i])); + if (mEvent === liveEvents[i]) break; } + return [...new Set(readers)]; }