Browse Source

Only ask for permission once the user is already logged in

updates #443
JC Brand 9 years ago
parent
commit
c793b846fb
2 changed files with 11 additions and 4 deletions
  1. 2 0
      src/converse-core.js
  2. 9 4
      src/converse-notification.js

+ 2 - 0
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) {

+ 9 - 4
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);
         }
     });
 }));