Fix live read recipt count (#227)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
4f161fb891
commit
e827fb2eb2
1 changed files with 38 additions and 26 deletions
|
@ -12,6 +12,20 @@ function isReaction(mEvent) {
|
||||||
return mEvent.getType() === 'm.reaction';
|
return mEvent.getType() === 'm.reaction';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hideMemberEvents(mEvent) {
|
||||||
|
const content = mEvent.getContent();
|
||||||
|
const prevContent = mEvent.getPrevContent();
|
||||||
|
const { membership } = content;
|
||||||
|
if (settings.hideMembershipEvents) {
|
||||||
|
if (membership === 'invite' || membership === 'ban' || membership === 'leave') return true;
|
||||||
|
if (prevContent.membership !== 'join') return true;
|
||||||
|
}
|
||||||
|
if (settings.hideNickAvatarEvents) {
|
||||||
|
if (membership === 'join' && prevContent.membership === 'join') return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function getRelateToId(mEvent) {
|
function getRelateToId(mEvent) {
|
||||||
const relation = mEvent.getRelation();
|
const relation = mEvent.getRelation();
|
||||||
return relation && relation.event_id;
|
return relation && relation.event_id;
|
||||||
|
@ -112,18 +126,8 @@ class RoomTimeline extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
addToTimeline(mEvent) {
|
addToTimeline(mEvent) {
|
||||||
if (mEvent.getType() === 'm.room.member' && (settings.hideMembershipEvents || settings.hideNickAvatarEvents)) {
|
if (mEvent.getType() === 'm.room.member' && hideMemberEvents(mEvent)) {
|
||||||
const content = mEvent.getContent();
|
return;
|
||||||
const prevContent = mEvent.getPrevContent();
|
|
||||||
const { membership } = content;
|
|
||||||
|
|
||||||
if (settings.hideMembershipEvents) {
|
|
||||||
if (membership === 'invite' || membership === 'ban' || membership === 'leave') return;
|
|
||||||
if (prevContent.membership !== 'join') return;
|
|
||||||
}
|
|
||||||
if (settings.hideNickAvatarEvents) {
|
|
||||||
if (membership === 'join' && prevContent.membership === 'join') return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mEvent.isRedacted()) return;
|
if (mEvent.isRedacted()) return;
|
||||||
if (isReaction(mEvent)) {
|
if (isReaction(mEvent)) {
|
||||||
|
@ -244,23 +248,10 @@ class RoomTimeline extends EventEmitter {
|
||||||
return this.room.getUnfilteredTimelineSet();
|
return this.room.getUnfilteredTimelineSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
getLiveReaders() {
|
|
||||||
const lastEvent = this.timeline[this.timeline.length - 1];
|
|
||||||
const liveEvents = this.liveTimeline.getEvents();
|
|
||||||
|
|
||||||
const readers = [];
|
|
||||||
|
|
||||||
for (let i = liveEvents.length - 1; i >= 0; i -= 1) {
|
|
||||||
readers.splice(readers.length, 0, ...this.room.getUsersReadUpTo(liveEvents[i]));
|
|
||||||
if (lastEvent === liveEvents[i]) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [...new Set(readers)];
|
|
||||||
}
|
|
||||||
|
|
||||||
getEventReaders(mEvent) {
|
getEventReaders(mEvent) {
|
||||||
const liveEvents = this.liveTimeline.getEvents();
|
const liveEvents = this.liveTimeline.getEvents();
|
||||||
const readers = [];
|
const readers = [];
|
||||||
|
if (!mEvent) return [];
|
||||||
|
|
||||||
for (let i = liveEvents.length - 1; i >= 0; i -= 1) {
|
for (let i = liveEvents.length - 1; i >= 0; i -= 1) {
|
||||||
readers.splice(readers.length, 0, ...this.room.getUsersReadUpTo(liveEvents[i]));
|
readers.splice(readers.length, 0, ...this.room.getUsersReadUpTo(liveEvents[i]));
|
||||||
|
@ -270,6 +261,27 @@ class RoomTimeline extends EventEmitter {
|
||||||
return [...new Set(readers)];
|
return [...new Set(readers)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLiveReaders() {
|
||||||
|
const liveEvents = this.liveTimeline.getEvents();
|
||||||
|
const getLatestVisibleEvent = () => {
|
||||||
|
for (let i = liveEvents.length - 1; i >= 0; i -= 1) {
|
||||||
|
const mEvent = liveEvents[i];
|
||||||
|
if (mEvent.getType() === 'm.room.member' && hideMemberEvents(mEvent)) {
|
||||||
|
// eslint-disable-next-line no-continue
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!mEvent.isRedacted()
|
||||||
|
&& !isReaction(mEvent)
|
||||||
|
&& !isEdited(mEvent)
|
||||||
|
&& cons.supportEventTypes.includes(mEvent.getType())
|
||||||
|
) return mEvent;
|
||||||
|
}
|
||||||
|
return liveEvents[liveEvents.length - 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.getEventReaders(getLatestVisibleEvent());
|
||||||
|
}
|
||||||
|
|
||||||
getUnreadEventIndex(readUpToEventId) {
|
getUnreadEventIndex(readUpToEventId) {
|
||||||
if (!this.hasEventInTimeline(readUpToEventId)) return -1;
|
if (!this.hasEventInTimeline(readUpToEventId)) return -1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue