Fix unable to mark as read some rooms
authorAjay Bura <ajbura@gmail.com>
Wed, 8 Dec 2021 08:19:47 +0000 (13:49 +0530)
committerAjay Bura <ajbura@gmail.com>
Wed, 8 Dec 2021 08:19:47 +0000 (13:49 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/organisms/room/Room.jsx
src/client/state/Notifications.js
src/client/state/RoomTimeline.js

index 0157ad84126f089021b200b0f7458699c7c18cc9..164e4909e8a74af3703f56aae09eb77253e4ad94 100644 (file)
@@ -19,7 +19,7 @@ function Room() {
   const mx = initMatrix.matrixClient;
   const handleRoomSelected = (rId, pRoomId, eId) => {
     if (mx.getRoom(rId)) {
-      setRoomTimeline(new RoomTimeline(rId));
+      setRoomTimeline(new RoomTimeline(rId, initMatrix.notifications));
       setEventId(eId);
     } else {
       // TODO: add ability to join room if roomId is invalid
index 476fd1b53ea9bdd93ee6d84f93db19a114c83639..e41dc8f3c894a58753cb70a8d2a6870115f4d401 100644 (file)
@@ -81,6 +81,13 @@ class Notifications extends EventEmitter {
     return this.roomIdToNoti.has(roomId);
   }
 
+  deleteNoti(roomId) {
+    if (this.hasNoti(roomId)) {
+      const noti = this.getNoti(roomId);
+      this._deleteNoti(roomId, noti.total, noti.highlight);
+    }
+  }
+
   _getAllParentIds(roomId) {
     let allParentIds = this.roomList.roomIdToParents.get(roomId);
     if (allParentIds === undefined) return new Set();
@@ -174,17 +181,13 @@ class Notifications extends EventEmitter {
         const readerUserId = Object.keys(content[readedEventId]['m.read'])[0];
         if (readerUserId !== this.matrixClient.getUserId()) return;
 
-        if (this.hasNoti(room.roomId)) {
-          const noti = this.getNoti(room.roomId);
-          this._deleteNoti(room.roomId, noti.total, noti.highlight);
-        }
+        this.deleteNoti(room.roomId);
       }
     });
 
     this.matrixClient.on('Room.myMembership', (room, membership) => {
       if (membership === 'leave' && this.hasNoti(room.roomId)) {
-        const noti = this.getNoti(room.roomId);
-        this._deleteNoti(room.roomId, noti.total, noti.highlight);
+        this.deleteNoti(room.roomId);
       }
     });
   }
index f56c6a89d6e4930ed8a3249545b38228336208c9..1b7eec695cd825bb71f9d62f3e55b64528c18324 100644 (file)
@@ -58,7 +58,7 @@ function isTimelineLinked(tm1, tm2) {
 }
 
 class RoomTimeline extends EventEmitter {
-  constructor(roomId) {
+  constructor(roomId, notifications) {
     super();
     // These are local timelines
     this.timeline = [];
@@ -69,6 +69,7 @@ class RoomTimeline extends EventEmitter {
     this.matrixClient = initMatrix.matrixClient;
     this.roomId = roomId;
     this.room = this.matrixClient.getRoom(roomId);
+    this.notifications = notifications;
 
     this.liveTimeline = this.room.getLiveTimeline();
     this.activeTimeline = this.liveTimeline;
@@ -208,6 +209,7 @@ class RoomTimeline extends EventEmitter {
 
   markAllAsRead() {
     const readEventId = this.getReadUpToEventId();
+    this.notifications.deleteNoti(this.roomId);
     if (this.timeline.length === 0) return;
     const latestEvent = this.timeline[this.timeline.length - 1];
     if (readEventId === latestEvent.getId()) return;
@@ -215,15 +217,6 @@ class RoomTimeline extends EventEmitter {
     this.emit(cons.events.roomTimeline.MARKED_AS_READ, latestEvent);
   }
 
-  markAsRead(eventId) {
-    if (this.hasEventInTimeline(eventId)) {
-      const mEvent = this.findEventById(eventId);
-      if (!mEvent) return;
-      this.matrixClient.sendReadReceipt(mEvent);
-      this.emit(cons.events.roomTimeline.MARKED_AS_READ, mEvent);
-    }
-  }
-
   hasEventInTimeline(eventId, timeline = this.activeTimeline) {
     const timelineSet = this.getUnfilteredTimelineSet();
     const eventTimeline = timelineSet.getTimelineForEvent(eventId);