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
This commit is contained in:
Eric Sethna 2019-09-16 12:01:10 -07:00 committed by Miguel Alatzar
parent d8d1e55610
commit 2c4764bc88
3 changed files with 15 additions and 11 deletions

View file

@ -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({

View file

@ -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(() => {

View file

@ -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",