Hopefully make unread loop a bit more digrestable.

This commit is contained in:
David Baker 2016-01-21 13:22:13 +00:00
parent 13e70e6956
commit 876646ac54

View file

@ -36,21 +36,27 @@ module.exports = {
// up probably won't be very much, so if the last couple of events are ones that // up probably won't be very much, so if the last couple of events are ones that
// don't count, we don't know if there are any events that do count between where // don't count, we don't know if there are any events that do count between where
// we have and the read receipt. We could fetch more history to try & find out, // we have and the read receipt. We could fetch more history to try & find out,
// but currently we just guess. This impl assumes there are unread messages // but currently we just guess.
// on the theory that false positives are better than false negatives here.
var unread = true; // Loop through messages, starting with the most recent...
for (var i = room.timeline.length - 1; i >= 0; --i) { for (var i = room.timeline.length - 1; i >= 0; --i) {
var ev = room.timeline[i]; var ev = room.timeline[i];
if (ev.getId() == readUpToId) { if (ev.getId() == readUpToId) {
unread = false; // If we've read up to this event, there's nothing more recents
break; // that counts and we can stop looking because the user's read
} // this and everything before.
return false;
if (this.eventTriggersUnreadCount(ev)) { } else if (this.eventTriggersUnreadCount(ev)) {
break; // We've found a message that counts before we hit
// the read marker, so this room is definitely unread.
return true;
} }
} }
return unread; // If we got here, we didn't find a message that counted but didn't
// find the read marker either, so we guess and say that the room
// is unread on the theory that false positives are better than
// false negatives here.
return true;
} }
}; };