fix: format 7/14 days to be a number of weeks for disappearing timer

pull/3206/head
Audric Ackermann 7 months ago
parent cc17285009
commit bf344329f8
No known key found for this signature in database

@ -107,7 +107,7 @@ export const CreateAccount = () => {
);
dispatch(setAccountCreationStep(AccountCreation.DisplayName));
// Note: we have to assume here that libsession threw an error because the name was too long.
// The error reporterd by libsession is not localized
// The error reported by libsession is not localized
dispatch(setDisplayNameError(window.i18n('displayNameErrorDescriptionShorter')));
}
};

@ -198,7 +198,7 @@ export const RestoreAccount = () => {
dispatch(setAccountRestorationStep(AccountRestoration.DisplayName));
// Note: we have to assume here that libsession threw an error because the name was too long.
// The error reporterd by libsession is not localized
// The error reported by libsession is not localized
dispatch(setDisplayNameError(window.i18n('displayNameErrorDescriptionShorter')));
}
};

@ -1,6 +1,8 @@
import { isDevProd } from '../../shared/env_vars';
import { formatAbbreviatedExpireTimer } from '../../util/i18n/formater/expirationTimer';
import { formatTimeDuration } from '../../util/i18n/formater/generics';
import {
formatAbbreviatedExpireTimer,
formatNonAbbreviatedExpireTimer,
} from '../../util/i18n/formater/expirationTimer';
import { DURATION_SECONDS } from '../constants';
type TimerOptionsEntry = { name: string; value: number };
@ -40,13 +42,13 @@ function getName(seconds = 0) {
return window.i18n('off');
}
if (seconds > 0) {
return formatTimeDuration(seconds * 1000);
return formatNonAbbreviatedExpireTimer(seconds);
}
return [seconds, 'seconds'].join(' ');
}
function getAbbreviated(seconds = 0) {
function getAbbreviated(seconds: number) {
if (seconds >= 0) {
return formatAbbreviatedExpireTimer(seconds);
}

@ -102,16 +102,10 @@ function getSelectedBlindedDisabledMsgRequests(state: StateType) {
}
/**
* Defaults to 'all' if undefined
* Defaults to 'all' if undefined/unset
*/
function getSelectedNotificationSetting(state: StateType) {
const selectedConvoPubkey = getSelectedConversationKey(state);
if (!selectedConvoPubkey) {
return false;
}
const selectedConvo = getSelectedConversation(state);
return selectedConvo?.currentNotificationSetting || 'all';
return getSelectedConversation(state)?.currentNotificationSetting || 'all';
}
const getSelectedConversationType = (state: StateType): ConversationTypeEnum | null => {

@ -1,6 +1,7 @@
import { Duration, formatDuration, intervalToDuration } from 'date-fns';
import { DURATION_SECONDS } from '../../../session/constants';
import { getForcedEnglishTimeLocale } from '../timeLocaleMap';
import { getTimeLocaleDictionary } from '../shared';
/**
* We decided against localizing the abbreviated durations like 1h, 1m, 1s as most apps don't.
@ -52,6 +53,12 @@ const secondsToDuration = (seconds: number): Duration => {
return duration;
};
function assertIsValidExpirationTimerSeconds(timerSeconds: number) {
if (timerSeconds > DURATION_SECONDS.WEEKS * 4) {
throw new Error('assertIsValidExpirationTimer is not design to handle >4 weeks durations ');
}
}
/**
* Format an expiring/disappearing message timer to its abbreviated form.
* Note: we don't localize this, and cannot have a value > 4 weeks
@ -60,9 +67,7 @@ const secondsToDuration = (seconds: number): Duration => {
* @returns '1h' for a duration of 3600s.
*/
export const formatAbbreviatedExpireTimer = (timerSeconds: number) => {
if (timerSeconds > DURATION_SECONDS.WEEKS * 4) {
throw new Error('formatAbbreviatedExpireTimer is not design to handle >4 weeks durations ');
}
assertIsValidExpirationTimerSeconds(timerSeconds);
if (timerSeconds <= 0) {
return window.i18n('off');
}
@ -76,6 +81,27 @@ export const formatAbbreviatedExpireTimer = (timerSeconds: number) => {
return unlocalizedDurationToAbbreviated(unlocalized);
};
/**
* Format an expiring/disappearing message timer to its full localized form.
* Note: throws if the value is > 4 weeks
*
* @param timerSeconds the timer to format, in seconds
* @returns '1hour' for a duration of 3600s.
*/
export const formatNonAbbreviatedExpireTimer = (timerSeconds: number) => {
assertIsValidExpirationTimerSeconds(timerSeconds);
if (timerSeconds <= 0) {
return window.i18n('off');
}
const duration = secondsToDuration(timerSeconds);
return formatDuration(duration, {
locale: getTimeLocaleDictionary(), // we want the full form to be localized
});
};
/**
* Format an expiring/disappearing message timer to its abbreviated form.
* Note: we don't localize this, and cannot have a value > 4 weeks

Loading…
Cancel
Save