Notifications: All calls are debounced except for shutdown clear
This commit is contained in:
parent
18a76ffb49
commit
b1a54c416f
2 changed files with 17 additions and 13 deletions
|
@ -240,7 +240,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('focus', () => Whisper.Notifications.clear());
|
window.addEventListener('focus', () => Whisper.Notifications.clear());
|
||||||
window.addEventListener('unload', () => Whisper.Notifications.clear());
|
window.addEventListener('unload', () => Whisper.Notifications.fastClear());
|
||||||
|
|
||||||
Whisper.events.on('showConversation', function(conversation) {
|
Whisper.events.on('showConversation', function(conversation) {
|
||||||
if (appView) {
|
if (appView) {
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
// to manually close them. This introduces a minimum amount of time between calls,
|
// to manually close them. This introduces a minimum amount of time between calls,
|
||||||
// and batches up the quick successive update() calls we get from an incoming
|
// and batches up the quick successive update() calls we get from an incoming
|
||||||
// read sync, which might have a number of messages referenced inside of it.
|
// read sync, which might have a number of messages referenced inside of it.
|
||||||
|
this.fastUpdate = this.update;
|
||||||
this.update = _.debounce(this.update, 1000);
|
this.update = _.debounce(this.update, 1000);
|
||||||
},
|
},
|
||||||
onClick(conversationId) {
|
onClick(conversationId) {
|
||||||
|
@ -43,6 +44,11 @@
|
||||||
this.trigger('click', conversation);
|
this.trigger('click', conversation);
|
||||||
},
|
},
|
||||||
update() {
|
update() {
|
||||||
|
if (this.lastNotification) {
|
||||||
|
this.lastNotification.close();
|
||||||
|
this.lastNotification = null;
|
||||||
|
}
|
||||||
|
|
||||||
const { isEnabled } = this;
|
const { isEnabled } = this;
|
||||||
const isAppFocused = isFocused();
|
const isAppFocused = isFocused();
|
||||||
const isAudioNotificationEnabled =
|
const isAudioNotificationEnabled =
|
||||||
|
@ -70,7 +76,7 @@
|
||||||
|
|
||||||
if (status.type !== 'ok') {
|
if (status.type !== 'ok') {
|
||||||
if (status.shouldClearNotifications) {
|
if (status.shouldClearNotifications) {
|
||||||
this.clear();
|
this.reset([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -136,9 +142,6 @@
|
||||||
|
|
||||||
drawAttention();
|
drawAttention();
|
||||||
|
|
||||||
if (this.lastNotification) {
|
|
||||||
this.lastNotification.close();
|
|
||||||
}
|
|
||||||
const notification = new Notification(title, {
|
const notification = new Notification(title, {
|
||||||
body: message,
|
body: message,
|
||||||
icon: iconUrl,
|
icon: iconUrl,
|
||||||
|
@ -159,18 +162,19 @@
|
||||||
},
|
},
|
||||||
onRemove() {
|
onRemove() {
|
||||||
console.log('Remove notification');
|
console.log('Remove notification');
|
||||||
if (this.length === 0) {
|
this.update();
|
||||||
this.clear();
|
|
||||||
} else {
|
|
||||||
this.update();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
clear() {
|
clear() {
|
||||||
console.log('Remove all notifications');
|
console.log('Remove all notifications');
|
||||||
if (this.lastNotification) {
|
|
||||||
this.lastNotification.close();
|
|
||||||
}
|
|
||||||
this.reset([]);
|
this.reset([]);
|
||||||
|
this.update();
|
||||||
|
},
|
||||||
|
// We don't usually call this, but when the process is shutting down, we should at
|
||||||
|
// least try to remove the notification immediately instead of waiting for the
|
||||||
|
// normal debounce.
|
||||||
|
fastClear() {
|
||||||
|
this.reset([]);
|
||||||
|
this.fastUpdate();
|
||||||
},
|
},
|
||||||
enable() {
|
enable() {
|
||||||
const needUpdate = !this.isEnabled;
|
const needUpdate = !this.isEnabled;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue