From a76db5b84f661f1254da6d04af5100f858051bb4 Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Mon, 29 Aug 2016 09:52:59 -0400
Subject: 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
---
 webapp/utils/utils.jsx | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

(limited to 'webapp/utils/utils.jsx')

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
                 }
-- 
cgit v1.2.3-1-g7c22

