Added options to enable polling and desktop notifications
authorAlexander Ebert <ebert@woltlab.com>
Mon, 29 May 2017 10:34:12 +0000 (12:34 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 29 May 2017 10:34:20 +0000 (12:34 +0200)
See #2279

com.woltlab.wcf/option.xml
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
constants.php
wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js

index 203d751f7b6ceb58793edefd6ddc40808867ed97..34b101ccc976351c2c35c7a7eaad4bdd3841ec12 100644 (file)
                                <defaultvalue>1</defaultvalue>
                                <options>module_wcf_ad</options>
                        </option>
+                       <option name="enable_polling">
+                               <categoryname>general.page</categoryname>
+                               <optiontype>boolean</optiontype>
+                               <defaultvalue>1</defaultvalue>
+                               <enableoptions>enable_desktop_notifications</enableoptions>
+                       </option>
+                       <option name="enable_desktop_notifications">
+                               <categoryname>general.page</categoryname>
+                               <optiontype>boolean</optiontype>
+                               <defaultvalue>1</defaultvalue>
+                       </option>
                        <option name="head_code">
                                <categoryname>general.page</categoryname>
                                <optiontype>textarea</optiontype>
index 2d4bd9e3dc9cf7542481f8b8718635620b0c40e5..360db269fd8699e2c09bed92416877ecf426f533 100644 (file)
@@ -202,9 +202,10 @@ requirejs.config({
                {if $__sessionKeepAlive|isset}
                        new WCF.System.KeepAlive({@$__sessionKeepAlive});
                        
-                       {if $__wcf->user->userID}
+                       {if ENABLE_POLLING && $__wcf->user->userID}
                                require(['WoltLabSuite/Core/Notification/Handler'], function(NotificationHandler) {
                                        NotificationHandler.setup({
+                                               enableNotifications: {if ENABLE_DESKTOP_NOTIFICATIONS}true{else}false{/if},
                                                icon: '{@$__wcf->getPath()}images/apple-touch-icon.png',
                                                sessionKeepAlive: {@$__sessionKeepAlive}
                                        });
index 7a9706ebb7ab56859091e0a274233bf76ef32b85..7d8f810aac9ebd432e773dd3947d2142582bdeca 100644 (file)
@@ -221,3 +221,5 @@ define('HEAD_CODE', '');
 define('AVATAR_DEFAULT_TYPE', 'initials');
 define('ARTICLE_ENABLE_VISIT_TRACKING', 1);
 define('ENABLE_AD_ROTATION', 1);
+define('ENABLE_POLLING', 1);
+define('ENABLE_DESKTOP_NOTIFICATIONS', 1);
index 57fdeca5c15fa3ae0e6b57e67b9a04ed1a3ba3a3..a14482305f886dee0635b34cb9756bdfc59e4fdd 100644 (file)
@@ -36,6 +36,7 @@ define(['Ajax', 'Core', 'EventHandler'], function(Ajax, Core, EventHandler) {
                 */
                setup: function (options) {
                        options = Core.extend({
+                               enableNotifications: false,
                                icon: '',
                                sessionKeepAlive: 0
                        }, options);
@@ -50,11 +51,13 @@ define(['Ajax', 'Core', 'EventHandler'], function(Ajax, Core, EventHandler) {
                        
                        this._onVisibilityChange();
                        
-                       window.Notification.requestPermission().then(function (result) {
-                               if (result === 'granted') {
-                                       _allowNotification = true;
-                               }
-                       });
+                       if (options.enableNotifications) {
+                               window.Notification.requestPermission().then(function (result) {
+                                       if (result === 'granted') {
+                                               _allowNotification = true;
+                                       }
+                               });
+                       }
                },
                
                /**