Close and redirect when clicking on desktop notifications
authorAlexander Ebert <ebert@woltlab.com>
Fri, 25 Aug 2017 11:12:27 +0000 (13:12 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 25 Aug 2017 11:12:32 +0000 (13:12 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js
wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php

index 46b33b4599937157ed7acfa86aa9e6bed4be7ebf..06b8556ff314c630dad3ede90a597d080e6c7d6c 100644 (file)
@@ -93,6 +93,9 @@ define(['Ajax', 'Core', 'EventHandler'], function(Ajax, Core, EventHandler) {
                 * @protected
                 */
                _getNextDelay: function() {
+                       // TODO: DEBUG ONLY
+                       return 1;
+                       
                        if (_inactiveSince === 0) return 5;
                        
                        // milliseconds -> minutes
@@ -224,10 +227,17 @@ define(['Ajax', 'Core', 'EventHandler'], function(Ajax, Core, EventHandler) {
                        //noinspection JSUnresolvedVariable
                        if (typeof pollData.notification === 'object' && typeof pollData.notification.message ===  'string') {
                                //noinspection JSUnresolvedVariable
-                               new window.Notification(pollData.notification.title, {
+                               var notification = new window.Notification(pollData.notification.title, {
                                        body: pollData.notification.message,
                                        icon: _icon
-                               })
+                               });
+                               notification.onclick = function () {
+                                       window.focus();
+                                       notification.close();
+                                       
+                                       //noinspection JSUnresolvedVariable
+                                       window.location = pollData.notification.link;
+                               };
                        }
                },
                
index 8962c7b48f551717c54e828257b12c6da934e510..33ef9826519291b65aee40ec0a523f23a58e9d3c 100644 (file)
@@ -18,6 +18,7 @@ use wcf\system\email\Email;
 use wcf\system\email\UserMailbox;
 use wcf\system\event\EventHandler;
 use wcf\system\exception\SystemException;
+use wcf\system\request\LinkHandler;
 use wcf\system\user\notification\event\IUserNotificationEvent;
 use wcf\system\user\notification\object\type\IUserNotificationObjectType;
 use wcf\system\user\notification\object\IUserNotificationObject;
@@ -919,7 +920,8 @@ class UserNotificationHandler extends SingletonFactory {
                                
                                return [
                                        'title' => strip_tags($event->getTitle()),
-                                       'message' => strip_tags($event->getMessage())
+                                       'message' => strip_tags($event->getMessage()),
+                                       'link' => LinkHandler::getInstance()->getLink('NotificationConfirm', ['id' => $event->getNotification()->notificationID])
                                ];
                        }
                }