diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-02-05 07:38:01 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2016-02-05 07:38:01 -0500 |
commit | 8e79f12f3c6c0f8858addaf6f66ea6e88a965b65 (patch) | |
tree | 77aaf0f5c38f63cb069cbd387fabc3f4e2d19b22 /web/react | |
parent | b6f29fd128b05049b18f066ceaa583173f91f085 (diff) | |
parent | 5cc359a4ea2f52ef787196d74b12b245ed62f249 (diff) | |
download | chat-8e79f12f3c6c0f8858addaf6f66ea6e88a965b65.tar.gz chat-8e79f12f3c6c0f8858addaf6f66ea6e88a965b65.tar.bz2 chat-8e79f12f3c6c0f8858addaf6f66ea6e88a965b65.zip |
Merge pull request #2077 from hmhealey/plt1819
PLT-1819 Changed notification permission dialogue to only be shown once per page load
Diffstat (limited to 'web/react')
-rw-r--r-- | web/react/utils/utils.jsx | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index e8cfc82bc..6bb7baa64 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -142,16 +142,24 @@ export function getCookie(name) { } } +var requestedNotificationPermission = false; + export function notifyMe(title, body, channel) { - if ('Notification' in window && Notification.permission !== 'denied') { - Notification.requestPermission(function onRequestPermission(permission) { + if (!('Notification' in window)) { + return; + } + + if (Notification.permission === 'granted' || (Notification.permission === 'default' && !requestedNotificationPermission)) { + requestedNotificationPermission = true; + + Notification.requestPermission((permission) => { if (Notification.permission !== permission) { Notification.permission = permission; } if (permission === 'granted') { - var notification = new Notification(title, {body: body, tag: body, icon: '/static/images/icon50x50.png'}); - notification.onclick = function onClick() { + var notification = new Notification(title, {body, tag: body, icon: '/static/images/icon50x50.png'}); + notification.onclick = () => { window.focus(); if (channel) { switchChannel(channel); @@ -159,7 +167,7 @@ export function notifyMe(title, body, channel) { window.location.href = TeamStore.getCurrentTeamUrl() + '/channels/town-square'; } }; - setTimeout(function closeNotificationOnTimeout() { + setTimeout(() => { notification.close(); }, 5000); } |