Close the notification after 10 seconds

This commit is contained in:
riking 2015-03-27 18:48:34 -07:00
parent c1528e598f
commit 84896bdccf
1 changed files with 13 additions and 6 deletions

View File

@ -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();
}
});