Show last seen indicator for keychange/verification notifications
FREEBIE
This commit is contained in:
parent
1fedc75e5d
commit
5b46ef3562
2 changed files with 34 additions and 15 deletions
|
@ -247,7 +247,8 @@
|
||||||
type : 'keychange',
|
type : 'keychange',
|
||||||
sent_at : this.get('timestamp'),
|
sent_at : this.get('timestamp'),
|
||||||
received_at : timestamp,
|
received_at : timestamp,
|
||||||
key_changed : id
|
key_changed : id,
|
||||||
|
unread : 1
|
||||||
});
|
});
|
||||||
message.save().then(this.trigger.bind(this,'newmessage', message));
|
message.save().then(this.trigger.bind(this,'newmessage', message));
|
||||||
},
|
},
|
||||||
|
@ -265,7 +266,8 @@
|
||||||
received_at : timestamp,
|
received_at : timestamp,
|
||||||
verifiedChanged : id,
|
verifiedChanged : id,
|
||||||
verified : verified,
|
verified : verified,
|
||||||
local : options.local
|
local : options.local,
|
||||||
|
unread : 1
|
||||||
});
|
});
|
||||||
message.save().then(this.trigger.bind(this,'newmessage', message));
|
message.save().then(this.trigger.bind(this,'newmessage', message));
|
||||||
|
|
||||||
|
@ -548,6 +550,14 @@
|
||||||
};
|
};
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
// Some messages we're marking read are local notifications with no sender
|
||||||
|
read = _.filter(read, function(m) {
|
||||||
|
return Boolean(m.sender);
|
||||||
|
});
|
||||||
|
unreadMessages = unreadMessages.filter(function(m) {
|
||||||
|
return Boolean(m.get('sender'));
|
||||||
|
});
|
||||||
|
|
||||||
var unreadCount = unreadMessages.length - read.length;
|
var unreadCount = unreadMessages.length - read.length;
|
||||||
this.save({ unreadCount: unreadCount });
|
this.save({ unreadCount: unreadCount });
|
||||||
|
|
||||||
|
|
|
@ -388,14 +388,25 @@
|
||||||
options = options || {};
|
options = options || {};
|
||||||
_.defaults(options, {scroll: true});
|
_.defaults(options, {scroll: true});
|
||||||
|
|
||||||
var oldestUnread = this.model.messageCollection.find(function(model) {
|
var unreadCount = 0;
|
||||||
return model.get('unread');
|
var oldestUnread = null;
|
||||||
|
|
||||||
|
// We need to iterate here because unseen non-messages do not contribute to
|
||||||
|
// the badge number, but should be reflected in the indicator's count.
|
||||||
|
this.model.messageCollection.forEach(function(model) {
|
||||||
|
if (!model.get('unread')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unreadCount += 1;
|
||||||
|
if (!oldestUnread) {
|
||||||
|
oldestUnread = model;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var unreadCount = this.model.get('unreadCount');
|
|
||||||
|
|
||||||
this.removeLastSeenIndicator();
|
this.removeLastSeenIndicator();
|
||||||
|
|
||||||
if (oldestUnread && unreadCount > 0) {
|
if (oldestUnread) {
|
||||||
this.lastSeenIndicator = new Whisper.LastSeenIndicatorView({count: unreadCount});
|
this.lastSeenIndicator = new Whisper.LastSeenIndicatorView({count: unreadCount});
|
||||||
var lastSeenEl = this.lastSeenIndicator.render().$el;
|
var lastSeenEl = this.lastSeenIndicator.render().$el;
|
||||||
|
|
||||||
|
@ -406,7 +417,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// scrollIntoView is an async operation, but we have no way to listen for
|
// scrollIntoView is an async operation, but we have no way to listen for
|
||||||
// completion of the resultant scroll.
|
// completion of the resultant scroll.
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
if (!this.view.atBottom()) {
|
if (!this.view.atBottom()) {
|
||||||
this.addScrollDownButtonWithCount(unreadCount);
|
this.addScrollDownButtonWithCount(unreadCount);
|
||||||
|
@ -523,18 +534,16 @@
|
||||||
var collection = this.model.messageCollection;
|
var collection = this.model.messageCollection;
|
||||||
var length = collection.length;
|
var length = collection.length;
|
||||||
var viewportBottom = this.view.outerHeight;
|
var viewportBottom = this.view.outerHeight;
|
||||||
var unreadCount = this.model.get('unreadCount');
|
var unreadCount = this.model.get('unreadCount') || 0;
|
||||||
|
|
||||||
if (!unreadCount || unreadCount < 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start with the most recent message, search backwards in time
|
// Start with the most recent message, search backwards in time
|
||||||
var foundUnread = 0;
|
var foundUnread = 0;
|
||||||
for (var i = length - 1; i >= 0; i -= 1) {
|
for (var i = length - 1; i >= 0; i -= 1) {
|
||||||
// We don't want to search through all messages, so we stop after we've
|
// Search the latest 30, then stop if we believe we've covered all known
|
||||||
// hit all unread messages. The unread should be relatively recent.
|
// unread messages. The unread should be relatively recent.
|
||||||
if (foundUnread >= unreadCount) {
|
// Why? local notifications can be unread but won't be reflected the
|
||||||
|
// conversation's unread count.
|
||||||
|
if (i > 30 && foundUnread >= unreadCount) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue