summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2016-02-04 16:51:32 -0500
committerhmhealey <harrisonmhealey@gmail.com>2016-02-04 16:51:32 -0500
commit5cc359a4ea2f52ef787196d74b12b245ed62f249 (patch)
treef0a3ad83013442632b222590a143d79d360176a0 /web
parentec51c31c325b3dc648a261f0e8634b6d70d7ba73 (diff)
downloadchat-5cc359a4ea2f52ef787196d74b12b245ed62f249.tar.gz
chat-5cc359a4ea2f52ef787196d74b12b245ed62f249.tar.bz2
chat-5cc359a4ea2f52ef787196d74b12b245ed62f249.zip
Changed notifications to only request permission once per session if the user clicks 'Not now' on Firefox
Diffstat (limited to 'web')
-rw-r--r--web/react/utils/utils.jsx18
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);
}