diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-08-29 09:52:59 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-08-29 09:52:59 -0400 |
commit | a76db5b84f661f1254da6d04af5100f858051bb4 (patch) | |
tree | b2b931c24b0b3a2fe622a1e2129186612fc82200 /webapp/utils/utils.jsx | |
parent | d252e61c662479155081aeaf34fe0c6e4c3705d1 (diff) | |
download | chat-a76db5b84f661f1254da6d04af5100f858051bb4.tar.gz chat-a76db5b84f661f1254da6d04af5100f858051bb4.tar.bz2 chat-a76db5b84f661f1254da6d04af5100f858051bb4.zip |
PLT-2074 Refactor desktop notification settings UI and add setting for duration (#3883)
* Refactor desktop notification settings UI and add setting for duration
* Update en.json
* Update desktop_notification_settings.jsx
Diffstat (limited to 'webapp/utils/utils.jsx')
-rw-r--r-- | webapp/utils/utils.jsx | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx index 3059ce529..2780196db 100644 --- a/webapp/utils/utils.jsx +++ b/webapp/utils/utils.jsx @@ -86,18 +86,23 @@ export function getCookie(name) { var requestedNotificationPermission = false; -export function notifyMe(title, body, channel, teamId) { +export function notifyMe(title, body, channel, teamId, duration) { if (!('Notification' in window)) { return; } + let notificationDuration = Constants.DEFAULT_NOTIFICATION_DURATION; + if (duration != null) { + notificationDuration = duration; + } + if (Notification.permission === 'granted' || (Notification.permission === 'default' && !requestedNotificationPermission)) { requestedNotificationPermission = true; Notification.requestPermission((permission) => { if (permission === 'granted') { try { - var notification = new Notification(title, {body, tag: body, icon: icon50}); + var notification = new Notification(title, {body, tag: body, icon: icon50, requireInteraction: notificationDuration === 0}); notification.onclick = () => { window.focus(); if (channel) { @@ -108,9 +113,12 @@ export function notifyMe(title, body, channel, teamId) { browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/town-square'); } }; - setTimeout(() => { - notification.close(); - }, 5000); + + if (notificationDuration > 0) { + setTimeout(() => { + notification.close(); + }, notificationDuration); + } } catch (e) { console.error(e); //eslint-disable-line no-console } |