Keep last seen indicator around for five seconds
Helps calm the user experience a little more, makes it easier to understand what's happening when messages are coming in quickly. FREEBIE
This commit is contained in:
parent
4e9e811d12
commit
01918049b4
3 changed files with 34 additions and 3 deletions
|
@ -251,8 +251,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
removeLastSeenIndicator: function() {
|
removeLastSeenIndicator: function(options) {
|
||||||
if (this.lastSeenIndicator) {
|
options = options || {};
|
||||||
|
_.defaults(options, {force: false});
|
||||||
|
|
||||||
|
if (this.lastSeenIndicator && (options.force || this.lastSeenIndicator.isOldEnough())) {
|
||||||
this.lastSeenIndicator.remove();
|
this.lastSeenIndicator.remove();
|
||||||
this.lastSeenIndicator = null;
|
this.lastSeenIndicator = null;
|
||||||
}
|
}
|
||||||
|
@ -275,7 +278,7 @@
|
||||||
options = options || {};
|
options = options || {};
|
||||||
_.defaults(options, {scroll: true});
|
_.defaults(options, {scroll: true});
|
||||||
|
|
||||||
this.removeLastSeenIndicator();
|
this.removeLastSeenIndicator({force: true});
|
||||||
|
|
||||||
var oldestUnread = this.model.messageCollection.find(function(model) {
|
var oldestUnread = this.model.messageCollection.find(function(model) {
|
||||||
return model.get('unread');
|
return model.get('unread');
|
||||||
|
@ -341,6 +344,12 @@
|
||||||
this.model.messageCollection.add(message, {merge: true});
|
this.model.messageCollection.add(message, {merge: true});
|
||||||
message.setToExpire();
|
message.setToExpire();
|
||||||
|
|
||||||
|
// if the last seen indicator is old enough, it will go away.
|
||||||
|
// if it isn't, we want to make sure it's up to date
|
||||||
|
if (this.lastSeenIndicator) {
|
||||||
|
this.lastSeenIndicator.increment(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.isHidden() && !window.isFocused()) {
|
if (!this.isHidden() && !window.isFocused()) {
|
||||||
this.updateLastSeenIndicator({scroll: false});
|
this.updateLastSeenIndicator({scroll: false});
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,27 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
|
|
||||||
|
var FIVE_SECONDS = 5 * 1000;
|
||||||
|
|
||||||
Whisper.LastSeenIndicatorView = Whisper.View.extend({
|
Whisper.LastSeenIndicatorView = Whisper.View.extend({
|
||||||
className: 'last-seen-indicator-view',
|
className: 'last-seen-indicator-view',
|
||||||
templateName: 'last-seen-indicator-view',
|
templateName: 'last-seen-indicator-view',
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
this.count = options.count || 0;
|
this.count = options.count || 0;
|
||||||
|
this.start = Date.now();
|
||||||
|
},
|
||||||
|
|
||||||
|
isOldEnough: function() {
|
||||||
|
var now = Date.now();
|
||||||
|
if (now - this.start > FIVE_SECONDS) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
increment: function(count) {
|
||||||
|
this.count += count;
|
||||||
|
this.render();
|
||||||
},
|
},
|
||||||
|
|
||||||
render_attributes: function() {
|
render_attributes: function() {
|
||||||
|
|
|
@ -9,4 +9,11 @@ describe('LastSeenIndicatorView', function() {
|
||||||
assert.equal(view.count, 10);
|
assert.equal(view.count, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('increments count', function() {
|
||||||
|
var view = new Whisper.LastSeenIndicatorView({count: 4});
|
||||||
|
assert.equal(view.count, 4);
|
||||||
|
view.increment(3);
|
||||||
|
assert.equal(view.count, 7);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue