diff --git a/src/app/organisms/room/Room.jsx b/src/app/organisms/room/Room.jsx index 0157ad84..164e4909 100644 --- a/src/app/organisms/room/Room.jsx +++ b/src/app/organisms/room/Room.jsx @@ -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 diff --git a/src/client/state/Notifications.js b/src/client/state/Notifications.js index 476fd1b5..e41dc8f3 100644 --- a/src/client/state/Notifications.js +++ b/src/client/state/Notifications.js @@ -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); } }); } diff --git a/src/client/state/RoomTimeline.js b/src/client/state/RoomTimeline.js index f56c6a89..1b7eec69 100644 --- a/src/client/state/RoomTimeline.js +++ b/src/client/state/RoomTimeline.js @@ -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);