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
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();
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);
}
});
}
}
class RoomTimeline extends EventEmitter {
- constructor(roomId) {
+ constructor(roomId, notifications) {
super();
// These are local timelines
this.timeline = [];
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;
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;
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);