From 84896bdccf89df9001a2d03ed784b4d6496cc85b Mon Sep 17 00:00:00 2001 From: riking Date: Fri, 27 Mar 2015 18:48:34 -0700 Subject: [PATCH] Close the notification after 10 seconds --- .../background-notifications.js.es6 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/background-notifications.js.es6 b/app/assets/javascripts/discourse/controllers/background-notifications.js.es6 index c056133269b..9bd1955a491 100644 --- a/app/assets/javascripts/discourse/controllers/background-notifications.js.es6 +++ b/app/assets/javascripts/discourse/controllers/background-notifications.js.es6 @@ -95,24 +95,31 @@ export default Discourse.Controller.extend({ }); const firstUnseen = unseen[0]; - notification.addEventListener('click', function() { - window.location.href = notificationUrl(firstUnseen); - window.focus(); - }); + + notification.addEventListener('click', self.clickEventHandler); + setTimeout(function() { + notification.close(); + notification.removeEventListener('click', self.clickEventHandler); + }, 10 * 1000); }); } }, + clickEventHandler() { + window.location.href = notificationUrl(firstUnseen); + window.focus(); + }, + // Utility function // Wraps Notification.requestPermission in a Promise requestPermission() { return new Ember.RSVP.Promise(function(resolve, reject) { - console.log('requesting'); Notification.requestPermission(function(status) { - console.log('requested, status:', status); if (status === "granted") { + Em.Logger.info('Discourse desktop notifications are enabled.'); resolve(); } else { + Em.Logger.info('Discourse desktop notifications are disabled.'); reject(); } });