From a01fac47535066758109b1715bc529812aeaca45 Mon Sep 17 00:00:00 2001 From: rashmibharambe <93034034+rashmibharambe@users.noreply.github.com> Date: Thu, 2 Nov 2023 21:08:57 +0530 Subject: [PATCH] Session timeout notification incorrectly says "Days" on iOS (#7629) * Session timeout notification incorrectly says "Days" on iOS * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Update index.ts * Session timeout notification incorrectly says "Days" on iOS * Update index.ts * Update en.json * Update index.ts --- app/utils/notification/index.ts | 25 ++++++++++++++++++++----- assets/base/i18n/en.json | 4 +++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/utils/notification/index.ts b/app/utils/notification/index.ts index b53c096c8..8460de9c9 100644 --- a/app/utils/notification/index.ts +++ b/app/utils/notification/index.ts @@ -90,12 +90,27 @@ export const emitNotificationError = (type: 'Team' | 'Channel' | 'Post' | 'Conne export const scheduleExpiredNotification = (serverUrl: string, session: Session, serverName: string, locale = DEFAULT_LOCALE) => { const expiresAt = session?.expires_at || 0; - const expiresInDays = Math.ceil(Math.abs(moment.duration(moment().diff(moment(expiresAt))).asDays())); + const expiresInHours = Math.ceil(Math.abs(moment.duration(moment().diff(moment(expiresAt))).asHours())); + const expiresInDays = Math.floor(expiresInHours / 24); // Calculate expiresInDays + const remainingHours = expiresInHours % 24; // Calculate remaining hours const intl = createIntl({locale, messages: getTranslations(locale)}); - const body = intl.formatMessage({ - id: 'mobile.session_expired', - defaultMessage: 'Please log in to continue receiving notifications. Sessions for {siteName} are configured to expire every {daysCount, number} {daysCount, plural, one {day} other {days}}.', - }, {siteName: serverName, daysCount: expiresInDays}); + let body = ''; + if (expiresInDays === 0) { + body = intl.formatMessage({ + id: 'mobile.session_expired_hrs', + defaultMessage: 'Please log in to continue receiving notifications. Sessions for {siteName} are configured to expire every {hoursCount, number} {hoursCount, plural, one {hour} other {hours}}.', + }, {siteName: serverName, hoursCount: remainingHours}); + } else if (expiresInHours === 0) { + body = intl.formatMessage({ + id: 'mobile.session_expired_days', + defaultMessage: 'Please log in to continue receiving notifications. Sessions for {siteName} are configured to expire every {daysCount, number} {daysCount, plural, one {day} other {days}}.', + }, {siteName: serverName, daysCount: expiresInDays}); + } else { + body = intl.formatMessage({ + id: 'mobile.session_expired_days_hrs', + defaultMessage: 'Please log in to continue receiving notifications. Sessions for {siteName} are configured to expire every {daysCount, number} {daysCount, plural, one {day} other {days}} and {hoursCount, number} {hoursCount, plural, one {hour} other {hours}}.', + }, {siteName: serverName, daysCount: expiresInDays, hoursCount: remainingHours}); + } const title = intl.formatMessage({id: 'mobile.session_expired.title', defaultMessage: 'Session Expired'}); if (expiresAt) { diff --git a/assets/base/i18n/en.json b/assets/base/i18n/en.json index 1e4606926..985b58325 100644 --- a/assets/base/i18n/en.json +++ b/assets/base/i18n/en.json @@ -710,7 +710,9 @@ "mobile.server_url.deeplink.emm.denied": "This app is controlled by an EMM and the DeepLink server url does not match the EMM allowed server", "mobile.server_url.empty": "Please enter a valid server URL", "mobile.server_url.invalid_format": "URL must start with http:// or https://", - "mobile.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.session_expired_days": "Please log in to continue receiving notifications. Sessions for {siteName} are configured to expire every {daysCount, number} {daysCount, plural, one {day} other {days}}.", + "mobile.session_expired_days_hrs": "Please log in to continue receiving notifications. Sessions for {siteName} are configured to expire every {daysCount, number} {daysCount, plural, one {day} other {days}} and {hoursCount, number} {hoursCount, plural, one {hour} other {hours}}.", + "mobile.session_expired_hrs": "Please log in to continue receiving notifications. Sessions for {siteName} are configured to expire every {hoursCount, number} {hoursCount, plural, one {hour} other {hours}}.", "mobile.session_expired.title": "Session Expired", "mobile.set_status.dnd": "Do Not Disturb", "mobile.storage_permission_denied_description": "Upload files to your server. Open Settings to grant {applicationName} Read and Write access to files on this device.",