Debounce updates to notifications and other events

Wait for one second of silence before displaying new notifications,
updating the unread count and conversation list previews.

Fixes #470
This commit is contained in:
lilia 2016-04-11 11:24:18 -07:00
parent ca28ba69d6
commit bb2868f1ec
3 changed files with 12 additions and 8 deletions

View file

@ -14,7 +14,7 @@
Whisper.Notifications = new (Backbone.Collection.extend({
initialize: function() {
this.on('add', this.onAdd);
this.on('add', _.debounce(this.update.bind(this), 1000));
this.on('remove', this.onRemove);
},
onclick: function() {
@ -30,6 +30,10 @@
this.clear();
},
update: function() {
extension.notification.clear();
if (this.length === 0) {
return;
}
var setting = storage.get('notification-setting') || 'message';
if (setting === SETTINGS.OFF) {
return;
@ -116,10 +120,6 @@
var setting = this.getSetting();
return (setting === SETTINGS.MESSAGE || setting === SETTINGS.NAME);
},
onAdd: function() {
extension.notification.clear();
this.update();
},
onRemove: function() {
if (this.length === 0) {
extension.notification.clear();