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