Skip to content

Commit c1db49f

Browse files
committed
feat: Update loading screen decyrption message [WPB-18629] (#19556)
1 parent c07ac48 commit c1db49f

File tree

7 files changed

+80
-19
lines changed

7 files changed

+80
-19
lines changed

src/i18n/de-DE.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,12 @@
10961096
"index.welcome": "Willkommen bei {brandName}!",
10971097
"initDecryption": "Entschlüssele Events",
10981098
"initEvents": "Nachrichten werden geladen",
1099-
"initProgress": "Loading messages from the last {time}",
1099+
"initProgressDaysPlural": "Lade Nachrichten der letzten {time} Tage",
1100+
"initProgressDaysSingular": "Lade Nachrichten des letzten {time} Tages",
1101+
"initProgressHoursPlural": "Lade Nachrichten der letzten {time} Stunden",
1102+
"initProgressHoursSingular": "Lade Nachrichten der letzten {time} Stunde",
1103+
"initProgressMinutesPlural": "Lade Nachrichten der letzten {time} Minuten",
1104+
"initProgressMinutesSingular": "Lade Nachrichten der letzten {time} Minute",
11001105
"initReceivedSelfUser": "Hallo, {user}.",
11011106
"initReceivedUserData": "Suche nach neuen Nachrichten",
11021107
"initUpdatedFromNotifications": "Fast fertig - viel Erfolg mit {brandName}",

src/i18n/en-US.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,12 @@
10961096
"index.welcome": "Welcome to {brandName}!",
10971097
"initDecryption": "Decrypting messages",
10981098
"initEvents": "Loading messages",
1099-
"initProgress": "Loading messages from the last {time}",
1099+
"initProgressDaysPlural": "Loading messages from the last {time} days",
1100+
"initProgressDaysSingular": "Loading messages from the last {time} day",
1101+
"initProgressHoursPlural": "Loading messages from the last {time} hours",
1102+
"initProgressHoursSingular": "Loading messages from the last {time} hour",
1103+
"initProgressMinutesPlural": "Loading messages from the last {time} minutes",
1104+
"initProgressMinutesSingular": "Loading messages from the last {time} minute",
11001105
"initReceivedSelfUser": "Hello, {user}.",
11011106
"initReceivedUserData": "Checking for new messages",
11021107
"initUpdatedFromNotifications": "Almost done - Enjoy {brandName}",

src/script/main/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ export class App {
563563
* even when app is already loaded and in the main screen view
564564
*/
565565
const message = this.config.FEATURE.SHOW_LOADING_INFORMATION
566-
? ` ${t('initProgress', {time: formatCoarseDuration(durationFrom(currentProcessingNotificationTimestamp))})}`
566+
? formatCoarseDuration(durationFrom(currentProcessingNotificationTimestamp))
567567
: '';
568568

569569
totalNotifications++;

src/script/util/DebugUtil.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ export class DebugUtil {
129129
const startTime = performance.now();
130130

131131
for (const notification of notificationResponse.notifications) {
132-
const events = this.core.service.notification.handleNotification(
132+
const events = this.core.service!.notification.handleNotification(
133133
notification,
134134
NotificationSource.NOTIFICATION_STREAM,
135-
false,
136135
);
137136

138137
for await (const event of events) {

src/script/util/TimeUtil.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -329,31 +329,30 @@ export const formatDelayTime = (delayTimeInMS: number): string => {
329329

330330
/**
331331
* Format duration into a coarse, human-readable unit:
332-
* - ≥ 1 day → "X days"
333-
* - ≥ 1 hour → "X hours"
334-
* - ≥ 1 min → "X minutes"
335-
* - < 1 min → "1 minute"
332+
* update the comments:
333+
* - > 1 day → "Loading messages from the last X days"
334+
* - > 24H → "Loading messages from the last 1 day"
335+
* - > 1 hour → "Loading messages from the last X hours"
336+
* - > 60 min → "Loading messages from the last 1 hour"
337+
* - > 1 min → "Loading messages from the last X minutes"
338+
* - > 60 sec → "Loading messages from the last 1 minute"
336339
*
337340
* @param duration - Duration in milliseconds
338341
* @returns Localized string of the coarsest applicable unit
339342
*/
340-
export const formatCoarseDuration = (duration: number): string => {
343+
export const formatCoarseDuration = (duration: number) => {
341344
if (duration >= TIME_IN_MILLIS.DAY) {
342345
const days = Math.floor(duration / TIME_IN_MILLIS.DAY);
343-
return `${days} ${t(`ephemeralUnitsDay${days === 1 ? '' : 's'}`)}`;
346+
return t(`initProgressDays${days === 1 ? 'Singular' : 'Plural'}`, {time: days});
344347
}
345348

346349
if (duration >= TIME_IN_MILLIS.HOUR) {
347350
const hours = Math.floor(duration / TIME_IN_MILLIS.HOUR);
348-
return `${hours} ${t(`ephemeralUnitsHour${hours === 1 ? '' : 's'}`)}`;
349-
}
350-
351-
if (duration >= TIME_IN_MILLIS.MINUTE) {
352-
const minutes = Math.floor(duration / TIME_IN_MILLIS.MINUTE);
353-
return `${minutes} ${t(`ephemeralUnitsMinute${minutes === 1 ? '' : 's'}`)}`;
351+
return t(`initProgressHours${hours === 1 ? 'Singular' : 'Plural'}`, {time: hours});
354352
}
355353

356-
return `1 ${t('ephemeralUnitsMinute')}`;
354+
const minutes = Math.max(1, Math.floor(duration / TIME_IN_MILLIS.MINUTE));
355+
return t(`initProgressMinutes${minutes === 1 ? 'Singular' : 'Plural'}`, {time: minutes});
357356
};
358357

359358
/**

src/types/i18n.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,12 @@ declare module 'I18n/en-US.json' {
10951095
'index.welcome': `Welcome to {brandName}!`;
10961096
'initDecryption': `Decrypting messages`;
10971097
'initEvents': `Loading messages`;
1098-
'initProgress': `Loading messages from {time} ago`;
1098+
'initProgressDaysPlural': `Loading messages from the last {time} days`;
1099+
'initProgressDaysSingular': `Loading messages from the last {time} day`;
1100+
'initProgressHoursPlural': `Loading messages from the last {time} hours`;
1101+
'initProgressHoursSingular': `Loading messages from the last {time} hour`;
1102+
'initProgressMinutesPlural': `Loading messages from the last {time} minutes`;
1103+
'initProgressMinutesSingular': `Loading messages from the last {time} minute`;
10991104
'initReceivedSelfUser': `Hello, {user}.`;
11001105
'initReceivedUserData': `Checking for new messages`;
11011106
'initUpdatedFromNotifications': `Almost done - Enjoy {brandName}`;

test/unit_tests/util/TimeUtilSpec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
formatDuration,
2525
formatDurationCaption,
2626
formatSeconds,
27+
formatCoarseDuration,
2728
isSameDay,
2829
isSameMonth,
2930
isThisYear,
@@ -316,6 +317,53 @@ describe('TimeUtil', () => {
316317
});
317318
});
318319

320+
describe('"formatCoarseDuration"', () => {
321+
it('formats durations in days (singular & plural)', () => {
322+
expect(formatCoarseDuration(ONE_DAY_IN_MILLIS)).toBe(t('initProgressDaysSingular', {time: 1}));
323+
324+
// Floor should keep it at 1 day
325+
expect(formatCoarseDuration(ONE_DAY_IN_MILLIS + 11 * ONE_HOUR_IN_MILLIS)).toBe(
326+
t('initProgressDaysSingular', {time: 1}),
327+
);
328+
329+
expect(formatCoarseDuration(2 * ONE_DAY_IN_MILLIS)).toBe(t('initProgressDaysPlural', {time: 2}));
330+
expect(formatCoarseDuration(2 * ONE_DAY_IN_MILLIS + 5 * ONE_HOUR_IN_MILLIS)).toBe(
331+
t('initProgressDaysPlural', {time: 2}),
332+
);
333+
});
334+
335+
it('formats durations in hours (singular & plural)', () => {
336+
expect(formatCoarseDuration(ONE_HOUR_IN_MILLIS)).toBe(t('initProgressHoursSingular', {time: 1}));
337+
338+
// Floor keeps it at 1 hour
339+
expect(formatCoarseDuration(ONE_HOUR_IN_MILLIS + 59 * ONE_MINUTE_IN_MILLIS)).toBe(
340+
t('initProgressHoursSingular', {time: 1}),
341+
);
342+
343+
expect(formatCoarseDuration(2 * ONE_HOUR_IN_MILLIS)).toBe(t('initProgressHoursPlural', {time: 2}));
344+
expect(formatCoarseDuration(2 * ONE_HOUR_IN_MILLIS + 30 * ONE_MINUTE_IN_MILLIS)).toBe(
345+
t('initProgressHoursPlural', {time: 2}),
346+
);
347+
});
348+
349+
it('formats durations in minutes (singular & plural)', () => {
350+
expect(formatCoarseDuration(ONE_MINUTE_IN_MILLIS)).toBe(t('initProgressMinutesSingular', {time: 1}));
351+
352+
// Floor keeps it at 1 minute
353+
expect(formatCoarseDuration(ONE_MINUTE_IN_MILLIS + 59 * ONE_SECOND_IN_MILLIS)).toBe(
354+
t('initProgressMinutesSingular', {time: 1}),
355+
);
356+
357+
expect(formatCoarseDuration(2 * ONE_MINUTE_IN_MILLIS)).toBe(t('initProgressMinutesPlural', {time: 2}));
358+
359+
// Sub-minute durations should be treated as 1 minute (singular)
360+
expect(formatCoarseDuration(59 * ONE_SECOND_IN_MILLIS)).toBe(t('initProgressMinutesSingular', {time: 1}));
361+
362+
// Explicit 30s case
363+
expect(formatCoarseDuration(30 * ONE_SECOND_IN_MILLIS)).toBe(t('initProgressMinutesSingular', {time: 1}));
364+
});
365+
});
366+
319367
describe('"formatSeconds"', () => {
320368
it('formats seconds', () => {
321369
expect(formatSeconds(50)).toBe('00:50');

0 commit comments

Comments
 (0)