From c793b846fb417b024ab97f2c142a0fc988bd7d4a Mon Sep 17 00:00:00 2001 From: JC Brand Date: Tue, 8 Mar 2016 22:36:13 +0000 Subject: [PATCH] Only ask for permission once the user is already logged in updates #443 --- src/converse-core.js | 2 ++ src/converse-notification.js | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/converse-core.js b/src/converse-core.js index b8d033b8d..dac9392ec 100755 --- a/src/converse-core.js +++ b/src/converse-core.js @@ -629,6 +629,7 @@ if (converse.disconnection_cause === Strophe.Status.CONNFAIL && converse.auto_reconnect) { converse.reconnect(condition); } else { + // FIXME: leaky abstraction from converse-controlbox.js converse.renderLoginPanel(); } } else if (status === Strophe.Status.ERROR) { @@ -646,6 +647,7 @@ } else if (status === Strophe.Status.DISCONNECTING) { // FIXME: what about prebind? if (!converse.connection.connected) { + // FIXME: leaky abstraction from converse-controlbox.js converse.renderLoginPanel(); } if (condition) { diff --git a/src/converse-notification.js b/src/converse-notification.js index bddd18e51..5e6bccfa3 100644 --- a/src/converse-notification.js +++ b/src/converse-notification.js @@ -20,10 +20,6 @@ var supports_html5_notification = "Notification" in window; - if (supports_html5_notification && Notification.permission !== 'denied') { - // Ask user to enable HTML5 notifications - Notification.requestPermission(); - } converse_api.plugins.add('notification', { @@ -195,9 +191,18 @@ } }; + converse.requestPermission = function (evt) { + if (supports_html5_notification && + ! _.contains(['denied', 'granted'], Notification.permission)) { + // Ask user to enable HTML5 notifications + Notification.requestPermission(); + } + }; + converse.on('contactRequest', converse.handleContactRequestNotification); converse.on('contactStatusChanged', converse.handleChatStateNotification); converse.on('message', converse.handleMessageNotification); + converse.on('ready', converse.requestPermission); } }); }));