Better ordering of ACI/E164 numbers

This commit is contained in:
Fedor Indutny 2023-07-19 01:40:14 +02:00 committed by Fedor Indutnyy
parent 1e6e8c3be4
commit eaae3ff88b
6 changed files with 26 additions and 17 deletions

View file

@ -27,7 +27,7 @@ export function SafetyNumberModal({
const { contact, safetyNumberMode } = safetyNumberViewerProps; const { contact, safetyNumberMode } = safetyNumberViewerProps;
const [isOnboarding, setIsOnboarding] = useState( const [isOnboarding, setIsOnboarding] = useState(
safetyNumberMode === SafetyNumberMode.ACIAndE164 && safetyNumberMode !== SafetyNumberMode.JustE164 &&
!hasCompletedSafetyNumberOnboarding !hasCompletedSafetyNumberOnboarding
); );
@ -40,10 +40,14 @@ export function SafetyNumberModal({
markHasCompletedSafetyNumberOnboarding(); markHasCompletedSafetyNumberOnboarding();
}, [setIsOnboarding, markHasCompletedSafetyNumberOnboarding]); }, [setIsOnboarding, markHasCompletedSafetyNumberOnboarding]);
const missingRequiredE164 =
safetyNumberMode !== SafetyNumberMode.DefaultACIAndMaybeE164 &&
!contact.e164;
let title: string | undefined; let title: string | undefined;
let content: JSX.Element; let content: JSX.Element;
let hasXButton = true; let hasXButton = true;
if (isSafetyNumberNotAvailable(contact)) { if (missingRequiredE164 || isSafetyNumberNotAvailable(contact)) {
content = ( content = (
<SafetyNumberNotReady <SafetyNumberNotReady
i18n={i18n} i18n={i18n}

View file

@ -73,7 +73,8 @@ const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
contact: overrideProps.contact || contactWithAllData, contact: overrideProps.contact || contactWithAllData,
generateSafetyNumber: action('generate-safety-number'), generateSafetyNumber: action('generate-safety-number'),
i18n, i18n,
safetyNumberMode: overrideProps.safetyNumberMode ?? SafetyNumberMode.ACI, safetyNumberMode:
overrideProps.safetyNumberMode ?? SafetyNumberMode.DefaultE164AndThenACI,
safetyNumbers: overrideProps.safetyNumbers ?? [ safetyNumbers: overrideProps.safetyNumbers ?? [
{ {
identifierType: SafetyNumberIdentifierType.ACIIdentifier, identifierType: SafetyNumberIdentifierType.ACIIdentifier,
@ -106,7 +107,7 @@ export function SafetyNumberBeforeE164Transition(): JSX.Element {
return ( return (
<SafetyNumberViewer <SafetyNumberViewer
{...createProps({ {...createProps({
safetyNumberMode: SafetyNumberMode.E164, safetyNumberMode: SafetyNumberMode.JustE164,
safetyNumbers: [ safetyNumbers: [
{ {
identifierType: SafetyNumberIdentifierType.E164Identifier, identifierType: SafetyNumberIdentifierType.E164Identifier,
@ -130,7 +131,7 @@ export function SafetyNumberE164Transition(): JSX.Element {
return ( return (
<SafetyNumberViewer <SafetyNumberViewer
{...createProps({ {...createProps({
safetyNumberMode: SafetyNumberMode.ACIAndE164, safetyNumberMode: SafetyNumberMode.DefaultE164AndThenACI,
safetyNumbers: [ safetyNumbers: [
{ {
identifierType: SafetyNumberIdentifierType.E164Identifier, identifierType: SafetyNumberIdentifierType.E164Identifier,

View file

@ -83,7 +83,7 @@ export function SafetyNumberViewer({
? i18n('icu:SafetyNumberViewer__clearVerification') ? i18n('icu:SafetyNumberViewer__clearVerification')
: i18n('icu:SafetyNumberViewer__markAsVerified'); : i18n('icu:SafetyNumberViewer__markAsVerified');
const isMigrationVisible = safetyNumberMode === SafetyNumberMode.ACIAndE164; const isMigrationVisible = safetyNumberMode !== SafetyNumberMode.JustE164;
const visibleSafetyNumber = safetyNumbers.at(selectedIndex); const visibleSafetyNumber = safetyNumbers.at(selectedIndex);
if (!visibleSafetyNumber) { if (!visibleSafetyNumber) {

View file

@ -175,19 +175,19 @@ export const getSafetyNumberMode = createSelector(
) && isBeta(window.getVersion()) ) && isBeta(window.getVersion())
) )
) { ) {
return SafetyNumberMode.E164; return SafetyNumberMode.JustE164;
} }
const timestamp = remoteConfig['global.safetyNumberAci']?.value; const timestamp = remoteConfig['global.safetyNumberAci']?.value;
if (typeof timestamp !== 'number') { if (typeof timestamp !== 'number') {
return SafetyNumberMode.ACIAndE164; return SafetyNumberMode.DefaultE164AndThenACI;
} }
// Note: serverTimeSkew is a difference between server time and local time, // Note: serverTimeSkew is a difference between server time and local time,
// so we have to add local time to it to correct it for a skew. // so we have to add local time to it to correct it for a skew.
return now + serverTimeSkew >= timestamp return now + serverTimeSkew >= timestamp
? SafetyNumberMode.ACI ? SafetyNumberMode.DefaultACIAndMaybeE164
: SafetyNumberMode.ACIAndE164; : SafetyNumberMode.DefaultE164AndThenACI;
} }
); );

View file

@ -2,9 +2,9 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
export enum SafetyNumberMode { export enum SafetyNumberMode {
E164 = 'E164', JustE164 = 'JustE164',
ACIAndE164 = 'ACIAndE164', DefaultE164AndThenACI = 'DefaultE164AndThenACI',
ACI = 'ACI', DefaultACIAndMaybeE164 = 'DefaultACIAndMaybeE164',
} }
export enum SafetyNumberIdentifierType { export enum SafetyNumberIdentifierType {

View file

@ -56,18 +56,22 @@ export async function generateSafetyNumbers(
const theirKey = PublicKey.deserialize(Buffer.from(theirKeyBuffer)); const theirKey = PublicKey.deserialize(Buffer.from(theirKeyBuffer));
let identifierTypes: ReadonlyArray<SafetyNumberIdentifierType>; let identifierTypes: ReadonlyArray<SafetyNumberIdentifierType>;
if (mode === SafetyNumberMode.ACIAndE164) { if (mode === SafetyNumberMode.DefaultE164AndThenACI) {
// Important: order matters, legacy safety number should be displayed first. // Important: order matters, legacy safety number should be displayed first.
identifierTypes = [ identifierTypes = [
SafetyNumberIdentifierType.E164Identifier, SafetyNumberIdentifierType.E164Identifier,
SafetyNumberIdentifierType.ACIIdentifier, SafetyNumberIdentifierType.ACIIdentifier,
]; ];
// Controlled by 'desktop.safetyNumberAci' // Controlled by 'desktop.safetyNumberAci'
} else if (mode === SafetyNumberMode.E164) { } else if (mode === SafetyNumberMode.JustE164) {
identifierTypes = [SafetyNumberIdentifierType.E164Identifier]; identifierTypes = [SafetyNumberIdentifierType.E164Identifier];
} else if (mode === SafetyNumberMode.DefaultACIAndMaybeE164) {
identifierTypes = [
SafetyNumberIdentifierType.ACIIdentifier,
SafetyNumberIdentifierType.E164Identifier,
];
} else { } else {
assertDev(mode === SafetyNumberMode.ACI, 'Invalid security number mode'); throw missingCaseError(mode);
identifierTypes = [SafetyNumberIdentifierType.ACIIdentifier];
} }
return identifierTypes return identifierTypes