From 41819838efa16036bae38e8079a7dbbfbf73d2a4 Mon Sep 17 00:00:00 2001 From: riking Date: Fri, 27 Mar 2015 19:11:41 -0700 Subject: [PATCH] Prevent "0 new notifications" --- .../background-notifications.js.es6 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/background-notifications.js.es6 b/app/assets/javascripts/discourse/controllers/background-notifications.js.es6 index 5a90a9cd4eb..b5eb0c9be01 100644 --- a/app/assets/javascripts/discourse/controllers/background-notifications.js.es6 +++ b/app/assets/javascripts/discourse/controllers/background-notifications.js.es6 @@ -63,7 +63,7 @@ export default Discourse.Controller.extend({ const unreadCount = unread.length; const unseenCount = unseen.length; - if (unseenCount === 0) { + if (unreadCount === 0 || unseenCount === 0) { return; } if (typeof document.hidden !== "undefined" && !document.hidden) { @@ -96,20 +96,22 @@ export default Discourse.Controller.extend({ const firstUnseen = unseen[0]; - notification.addEventListener('click', self.clickEventHandler); + function clickEventHandler() { + Discourse.URL.routeTo(notificationUrl(firstUnseen)); + // Cannot delay this until the page renders :( + // due to trigger-based permissions + window.focus(); + } + + notification.addEventListener('click', clickEventHandler); setTimeout(function() { notification.close(); - notification.removeEventListener('click', self.clickEventHandler); + notification.removeEventListener('click', clickEventHandler); }, 10 * 1000); }); } }, - clickEventHandler() { - Discourse.URL.routeTo(notificationUrl(firstUnseen)); - window.focus(); - }, - // Utility function // Wraps Notification.requestPermission in a Promise requestPermission() {