Changed notifications to only request permission once per session if the user clicks 'Not now' on Firefox

Этот коммит содержится в:
hmhealey
2016-02-04 16:51:32 -05:00
родитель ec51c31c32
Коммит 5cc359a4ea

Просмотреть файл

@@ -142,16 +142,24 @@ export function getCookie(name) {
} }
} }
var requestedNotificationPermission = false;
export function notifyMe(title, body, channel) { export function notifyMe(title, body, channel) {
if ('Notification' in window && Notification.permission !== 'denied') { if (!('Notification' in window)) {
Notification.requestPermission(function onRequestPermission(permission) { return;
}
if (Notification.permission === 'granted' || (Notification.permission === 'default' && !requestedNotificationPermission)) {
requestedNotificationPermission = true;
Notification.requestPermission((permission) => {
if (Notification.permission !== permission) { if (Notification.permission !== permission) {
Notification.permission = permission; Notification.permission = permission;
} }
if (permission === 'granted') { if (permission === 'granted') {
var notification = new Notification(title, {body: body, tag: body, icon: '/static/images/icon50x50.png'}); var notification = new Notification(title, {body, tag: body, icon: '/static/images/icon50x50.png'});
notification.onclick = function onClick() { notification.onclick = () => {
window.focus(); window.focus();
if (channel) { if (channel) {
switchChannel(channel); switchChannel(channel);
@@ -159,7 +167,7 @@ export function notifyMe(title, body, channel) {
window.location.href = TeamStore.getCurrentTeamUrl() + '/channels/town-square'; window.location.href = TeamStore.getCurrentTeamUrl() + '/channels/town-square';
} }
}; };
setTimeout(function closeNotificationOnTimeout() { setTimeout(() => {
notification.close(); notification.close();
}, 5000); }, 5000);
} }