Fix unable to mark as read some rooms
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
ca55141276
commit
27d0a88b36
3 changed files with 13 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue