From d6a9038198a76ab9b289b274fd6311ff82361dd2 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 25 Feb 2020 15:19:42 +1100 Subject: [PATCH 1/3] enable back notifications --- js/background.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/background.js b/js/background.js index 5ce84a8fc..3ea8d48cc 100644 --- a/js/background.js +++ b/js/background.js @@ -1470,7 +1470,8 @@ serverTrustRoot: window.getServerTrustRoot(), }; - Whisper.Notifications.disable(); // avoid notification flood until empty + // Whisper.Notifications.disable(); // avoid notification flood until empty + Whisper.Notifications.enable(); if (Whisper.Registration.ongoingSecondaryDeviceRegistration()) { const ourKey = textsecure.storage.user.getNumber(); @@ -1642,7 +1643,7 @@ // scenarios where we're coming back from sleep, we can get offline/online events // very fast, and it looks like a network blip. But we need to suppress // notifications in these scenarios too. So we listen for 'reconnect' events. - Whisper.Notifications.disable(); + // Whisper.Notifications.disable(); } function onProgress(ev) { const { count } = ev; From f5b3eb394c9b0dcce9c86d316063f0d04d7be575 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 25 Feb 2020 16:08:56 +1100 Subject: [PATCH 2/3] enable notifications after 10seconds of start or reconnect --- js/background.js | 13 ++++++++++--- preload.js | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/js/background.js b/js/background.js index 3ea8d48cc..910c4b1bd 100644 --- a/js/background.js +++ b/js/background.js @@ -1470,8 +1470,10 @@ serverTrustRoot: window.getServerTrustRoot(), }; - // Whisper.Notifications.disable(); // avoid notification flood until empty - Whisper.Notifications.enable(); + Whisper.Notifications.disable(); // avoid notification flood until empty + setTimeout(() => { + Whisper.Notifications.enable(); + }, window.CONSTANTS.NOTIFICATION_ENABLE_TIMEOUT_SECONDS * 1000); if (Whisper.Registration.ongoingSecondaryDeviceRegistration()) { const ourKey = textsecure.storage.user.getNumber(); @@ -1643,7 +1645,12 @@ // scenarios where we're coming back from sleep, we can get offline/online events // very fast, and it looks like a network blip. But we need to suppress // notifications in these scenarios too. So we listen for 'reconnect' events. - // Whisper.Notifications.disable(); + Whisper.Notifications.disable(); + + // Enable back notifications once most messages have been fetched + setTimeout(() => { + Whisper.Notifications.enable(); + }, window.CONSTANTS.NOTIFICATION_ENABLE_TIMEOUT_SECONDS * 1000); } function onProgress(ev) { const { count } = ev; diff --git a/preload.js b/preload.js index d701ff174..c9383e136 100644 --- a/preload.js +++ b/preload.js @@ -70,6 +70,7 @@ window.CONSTANTS = { MAX_MESSAGE_BODY_LENGTH: 64 * 1024, // Limited due to the proof-of-work requirement SMALL_GROUP_SIZE_LIMIT: 10, + NOTIFICATION_ENABLE_TIMEOUT_SECONDS: 10, // number of seconds to turn on notifications after reconnect/start of app }; window.versionInfo = { From ff8c2fc050732a8ac864ff355e8b4e63e7914f87 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 25 Feb 2020 16:09:14 +1100 Subject: [PATCH 3/3] debounce notifications update to 2sec --- js/notifications.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/notifications.js b/js/notifications.js index d053ea717..da6935725 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -34,8 +34,6 @@ Whisper.Notifications = new (Backbone.Collection.extend({ initialize() { this.isEnabled = false; - this.on('add', this.update); - this.on('remove', this.onRemove); this.lastNotification = null; @@ -45,7 +43,11 @@ // 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. this.fastUpdate = this.update; - this.update = _.debounce(this.update, 1000); + this.update = _.debounce(this.update, 2000); + + // make those calls use the debounced function + this.on('add', this.update); + this.on('remove', this.onRemove); }, update() { if (this.lastNotification) {