Mark messages read only when visible, on receipt, focus, scroll

- Only mark messages read when scrolling if in focus and visible
- Remove last seen indicator when scrolling to the bottom with scroll
  down button
- Update last seen indicator when we don't already have one and we're
  scrolled up.

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-05-30 17:29:23 -07:00
parent 9a0a87ab40
commit b60b20bde4
3 changed files with 94 additions and 12 deletions

View file

@ -71,7 +71,7 @@
}.bind(this));
},
getUnread: function() {
getUnread: function(newestUnreadDate) {
var conversationId = this.id;
var unreadMessages = new Whisper.MessageCollection();
return new Promise(function(resolve) {
@ -83,7 +83,15 @@
upper : [conversationId, Number.MAX_VALUE],
}
}).always(function() {
resolve(unreadMessages);
if (!newestUnreadDate) {
return resolve(unreadMessages);
}
// TODO: look into an index which would allow us to efficiently get the
// set of unread messages before a certain date.
resolve(unreadMessages.filter(function(message) {
return message.get('received_at') <= newestUnreadDate;
}));
});
});
@ -291,15 +299,14 @@
}
},
markRead: function() {
markRead: function(newestUnreadDate) {
if (this.get('unreadCount') > 0) {
this.save({ unreadCount: 0 });
var conversationId = this.id;
Whisper.Notifications.remove(Whisper.Notifications.where({
conversationId: conversationId
}));
this.getUnread().then(function(unreadMessages) {
this.getUnread(newestUnreadDate).then(function(unreadMessages) {
var read = unreadMessages.map(function(m) {
if (this.messageCollection.get(m.id)) {
m = this.messageCollection.get(m.id);
@ -313,7 +320,16 @@
timestamp : m.get('sent_at')
};
}.bind(this));
if (read.length > 0) {
var unreadCount = this.get('unreadCount');
unreadCount = unreadCount - read.length;
if (unreadCount < 0) {
console.log('conversation unreadCount went below zero!');
unreadCount = 0;
}
this.save({ unreadCount: unreadCount });
console.log('Sending', read.length, 'read receipts');
textsecure.messaging.syncReadMessages(read);
}