Clear notification when the last one is removed

Previously, we switched to not updating the notification popup on a
removal, since this usually respawns a new notification popup
unexpectedly. However, when the last relevant notification is cleared
(ie, by opening/reading the thread before the notification times out and
disappears on its own) we should clear the existing popup if there is
one.

// FREEBIE
This commit is contained in:
lilia 2016-02-22 12:55:19 -08:00
parent 1f897f32b7
commit f7191ad9de

View file

@ -15,6 +15,7 @@
Whisper.Notifications = new (Backbone.Collection.extend({ Whisper.Notifications = new (Backbone.Collection.extend({
initialize: function() { initialize: function() {
this.on('add', this.onAdd); this.on('add', this.onAdd);
this.on('remove', this.onRemove);
}, },
onclick: function() { onclick: function() {
var last = this.last(); var last = this.last();
@ -29,11 +30,6 @@
this.clear(); this.clear();
}, },
update: function() { update: function() {
if (this.length === 0) {
extension.notification.clear();
return;
}
var setting = storage.get('notification-setting') || 'message'; var setting = storage.get('notification-setting') || 'message';
if (setting === SETTINGS.OFF) { if (setting === SETTINGS.OFF) {
return; return;
@ -124,6 +120,12 @@
extension.notification.clear(); extension.notification.clear();
this.update(); this.update();
}, },
onRemove: function() {
if (this.length === 0) {
extension.notification.clear();
return;
}
},
clear: function() { clear: function() {
this.reset([]); this.reset([]);
} }