From 2c4764bc88f8996795732655c139bbb870bcc287 Mon Sep 17 00:00:00 2001 From: Eric Sethna Date: Mon, 16 Sep 2019 12:01:10 -0700 Subject: [PATCH] Update session expiry push notification text (#3211) * Update session expiry text * Calculate the session expires in days to be displayed in the local notification * Feedback review --- app/actions/views/login.js | 16 ++++++++++++---- app/utils/push_notifications.js | 8 ++------ assets/base/i18n/en.json | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/actions/views/login.js b/app/actions/views/login.js index f84d97b9d..1f60a15a3 100644 --- a/app/actions/views/login.js +++ b/app/actions/views/login.js @@ -1,6 +1,8 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import moment from 'moment-timezone'; + import {getDataRetentionPolicy} from 'mattermost-redux/actions/general'; import {GeneralTypes} from 'mattermost-redux/action_types'; import {getSessions} from 'mattermost-redux/actions/users'; @@ -75,10 +77,7 @@ export function scheduleExpiredNotification(intl) { const state = getState(); const {currentUserId} = state.entities.users; const {deviceToken} = state.entities.general; - const message = intl.formatMessage({ - id: 'mobile.session_expired', - defaultMessage: 'Session Expired: Please log in to continue receiving notifications.', - }); + const config = getConfig(state); // Once the user logs in we are going to wait for 10 seconds // before retrieving the session that belongs to this device @@ -99,6 +98,15 @@ export function scheduleExpiredNotification(intl) { const session = sessions.data.find((s) => s.device_id === deviceToken); const expiresAt = session?.expires_at || 0; //eslint-disable-line camelcase + const expiresInDays = parseInt(Math.ceil(Math.abs(moment.duration(moment().diff(expiresAt)).asDays())), 10); + + const message = intl.formatMessage({ + id: 'mobile.session_expired', + defaultMessage: 'Session Expired: Please log in to continue receiving notifications. Sessions for {siteName} are configured to expire every {daysCount, number} {daysCount, plural, one {day} other {days}}.', + }, { + siteName: config.SiteName, + daysCount: expiresInDays, + }); if (expiresAt) { PushNotifications.localNotificationSchedule({ diff --git a/app/utils/push_notifications.js b/app/utils/push_notifications.js index 5e91342e1..265388db8 100644 --- a/app/utils/push_notifications.js +++ b/app/utils/push_notifications.js @@ -66,16 +66,12 @@ class PushNotificationUtils { let unsubscribeFromStore = null; let stopLoadingNotification = false; - const {data, foreground, message, userInfo, userInteraction} = deviceNotification; + const {data, foreground, message, userInteraction} = deviceNotification; const notification = { data, message, }; - if (userInfo) { - notification.localNotification = userInfo.localNotification; - } - if (data.type === 'clear') { dispatch(markChannelViewedAndRead(data.channel_id, null, false)); } else { @@ -84,7 +80,7 @@ class PushNotificationUtils { if (foreground) { EventEmitter.emit(ViewTypes.NOTIFICATION_IN_APP, notification); - } else if (userInteraction && !notification.localNotification) { + } else if (userInteraction && !notification?.data?.localNotification) { EventEmitter.emit('close_channel_drawer'); if (getState().views.root.hydrationComplete) { //TODO: Replace when realm is ready setTimeout(() => { diff --git a/assets/base/i18n/en.json b/assets/base/i18n/en.json index e5bc7d6ee..e0fde4738 100644 --- a/assets/base/i18n/en.json +++ b/assets/base/i18n/en.json @@ -434,7 +434,7 @@ "mobile.server_upgrade.description": "\nA server upgrade is required to use the Mattermost app. Please ask your System Administrator for details.\n", "mobile.server_upgrade.title": "Server upgrade required", "mobile.server_url.invalid_format": "URL must start with http:// or https://", - "mobile.session_expired": "Session Expired: Please log in to continue receiving notifications.", + "mobile.session_expired": "Session Expired: Please log in to continue receiving notifications. Sessions for {siteName} are configured to expire every {daysCount, number} {daysCount, plural, one {day} other {days}}.", "mobile.set_status.away": "Away", "mobile.set_status.dnd": "Do Not Disturb", "mobile.set_status.offline": "Offline",