From: Alexander Ebert Date: Fri, 25 Aug 2017 11:12:27 +0000 (+0200) Subject: Close and redirect when clicking on desktop notifications X-Git-Tag: 3.1.0_Alpha_2~25^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f9076d74df144f4d3b7930e43c34ab78d6356249;p=GitHub%2FWoltLab%2FWCF.git Close and redirect when clicking on desktop notifications --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js index 46b33b4599..06b8556ff3 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/Handler.js @@ -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; + }; } }, diff --git a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php index 8962c7b48f..33ef982651 100644 --- a/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php @@ -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]) ]; } }