From a76db5b84f661f1254da6d04af5100f858051bb4 Mon Sep 17 00:00:00 2001 From: Joram Wilander 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/constants.jsx | 3 ++- webapp/utils/utils.jsx | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'webapp/utils') diff --git a/webapp/utils/constants.jsx b/webapp/utils/constants.jsx index 60cc82ff6..1ec20d3e8 100644 --- a/webapp/utils/constants.jsx +++ b/webapp/utils/constants.jsx @@ -809,7 +809,8 @@ export const Constants = { PERMISSIONS_SYSTEM_ADMIN: 'system_admin', MENTION_MEMBERS: 'mention.members', MENTION_NONMEMBERS: 'mention.nonmembers', - MENTION_SPECIAL: 'mention.special' + MENTION_SPECIAL: 'mention.special', + DEFAULT_NOTIFICATION_DURATION: 5000 }; export default Constants; 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