Comment & change the default to assuming there are unread messages.

pull/21833/head
David Baker 2016-01-06 18:28:13 +00:00
parent 04c7792b51
commit 76177378f3
1 changed files with 9 additions and 2 deletions

View File

@ -32,16 +32,23 @@ module.exports = {
doesRoomHaveUnreadMessages: function(room) { doesRoomHaveUnreadMessages: function(room) {
var readUpToId = room.getEventReadUpTo(MatrixClientPeg.get().credentials.userId); var readUpToId = room.getEventReadUpTo(MatrixClientPeg.get().credentials.userId);
var unread = false; // this just looks at whatever history we have, which if we've only just started
// 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
// 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
// on the theory that false positives are better than false negatives here.
var unread = true;
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;
break; break;
} }
if (this.eventTriggersUnreadCount(ev)) { if (this.eventTriggersUnreadCount(ev)) {
unread = true; break;
} }
} }
return unread; return unread;