Better ordering of ACI/E164 numbers
This commit is contained in:
parent
1e6e8c3be4
commit
eaae3ff88b
6 changed files with 26 additions and 17 deletions
|
@ -27,7 +27,7 @@ export function SafetyNumberModal({
|
|||
const { contact, safetyNumberMode } = safetyNumberViewerProps;
|
||||
|
||||
const [isOnboarding, setIsOnboarding] = useState(
|
||||
safetyNumberMode === SafetyNumberMode.ACIAndE164 &&
|
||||
safetyNumberMode !== SafetyNumberMode.JustE164 &&
|
||||
!hasCompletedSafetyNumberOnboarding
|
||||
);
|
||||
|
||||
|
@ -40,10 +40,14 @@ export function SafetyNumberModal({
|
|||
markHasCompletedSafetyNumberOnboarding();
|
||||
}, [setIsOnboarding, markHasCompletedSafetyNumberOnboarding]);
|
||||
|
||||
const missingRequiredE164 =
|
||||
safetyNumberMode !== SafetyNumberMode.DefaultACIAndMaybeE164 &&
|
||||
!contact.e164;
|
||||
|
||||
let title: string | undefined;
|
||||
let content: JSX.Element;
|
||||
let hasXButton = true;
|
||||
if (isSafetyNumberNotAvailable(contact)) {
|
||||
if (missingRequiredE164 || isSafetyNumberNotAvailable(contact)) {
|
||||
content = (
|
||||
<SafetyNumberNotReady
|
||||
i18n={i18n}
|
||||
|
|
|
@ -73,7 +73,8 @@ const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
|
|||
contact: overrideProps.contact || contactWithAllData,
|
||||
generateSafetyNumber: action('generate-safety-number'),
|
||||
i18n,
|
||||
safetyNumberMode: overrideProps.safetyNumberMode ?? SafetyNumberMode.ACI,
|
||||
safetyNumberMode:
|
||||
overrideProps.safetyNumberMode ?? SafetyNumberMode.DefaultE164AndThenACI,
|
||||
safetyNumbers: overrideProps.safetyNumbers ?? [
|
||||
{
|
||||
identifierType: SafetyNumberIdentifierType.ACIIdentifier,
|
||||
|
@ -106,7 +107,7 @@ export function SafetyNumberBeforeE164Transition(): JSX.Element {
|
|||
return (
|
||||
<SafetyNumberViewer
|
||||
{...createProps({
|
||||
safetyNumberMode: SafetyNumberMode.E164,
|
||||
safetyNumberMode: SafetyNumberMode.JustE164,
|
||||
safetyNumbers: [
|
||||
{
|
||||
identifierType: SafetyNumberIdentifierType.E164Identifier,
|
||||
|
@ -130,7 +131,7 @@ export function SafetyNumberE164Transition(): JSX.Element {
|
|||
return (
|
||||
<SafetyNumberViewer
|
||||
{...createProps({
|
||||
safetyNumberMode: SafetyNumberMode.ACIAndE164,
|
||||
safetyNumberMode: SafetyNumberMode.DefaultE164AndThenACI,
|
||||
safetyNumbers: [
|
||||
{
|
||||
identifierType: SafetyNumberIdentifierType.E164Identifier,
|
||||
|
|
|
@ -83,7 +83,7 @@ export function SafetyNumberViewer({
|
|||
? i18n('icu:SafetyNumberViewer__clearVerification')
|
||||
: i18n('icu:SafetyNumberViewer__markAsVerified');
|
||||
|
||||
const isMigrationVisible = safetyNumberMode === SafetyNumberMode.ACIAndE164;
|
||||
const isMigrationVisible = safetyNumberMode !== SafetyNumberMode.JustE164;
|
||||
|
||||
const visibleSafetyNumber = safetyNumbers.at(selectedIndex);
|
||||
if (!visibleSafetyNumber) {
|
||||
|
|
|
@ -175,19 +175,19 @@ export const getSafetyNumberMode = createSelector(
|
|||
) && isBeta(window.getVersion())
|
||||
)
|
||||
) {
|
||||
return SafetyNumberMode.E164;
|
||||
return SafetyNumberMode.JustE164;
|
||||
}
|
||||
|
||||
const timestamp = remoteConfig['global.safetyNumberAci']?.value;
|
||||
if (typeof timestamp !== 'number') {
|
||||
return SafetyNumberMode.ACIAndE164;
|
||||
return SafetyNumberMode.DefaultE164AndThenACI;
|
||||
}
|
||||
|
||||
// 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.
|
||||
return now + serverTimeSkew >= timestamp
|
||||
? SafetyNumberMode.ACI
|
||||
: SafetyNumberMode.ACIAndE164;
|
||||
? SafetyNumberMode.DefaultACIAndMaybeE164
|
||||
: SafetyNumberMode.DefaultE164AndThenACI;
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
export enum SafetyNumberMode {
|
||||
E164 = 'E164',
|
||||
ACIAndE164 = 'ACIAndE164',
|
||||
ACI = 'ACI',
|
||||
JustE164 = 'JustE164',
|
||||
DefaultE164AndThenACI = 'DefaultE164AndThenACI',
|
||||
DefaultACIAndMaybeE164 = 'DefaultACIAndMaybeE164',
|
||||
}
|
||||
|
||||
export enum SafetyNumberIdentifierType {
|
||||
|
|
|
@ -56,18 +56,22 @@ export async function generateSafetyNumbers(
|
|||
const theirKey = PublicKey.deserialize(Buffer.from(theirKeyBuffer));
|
||||
|
||||
let identifierTypes: ReadonlyArray<SafetyNumberIdentifierType>;
|
||||
if (mode === SafetyNumberMode.ACIAndE164) {
|
||||
if (mode === SafetyNumberMode.DefaultE164AndThenACI) {
|
||||
// Important: order matters, legacy safety number should be displayed first.
|
||||
identifierTypes = [
|
||||
SafetyNumberIdentifierType.E164Identifier,
|
||||
SafetyNumberIdentifierType.ACIIdentifier,
|
||||
];
|
||||
// Controlled by 'desktop.safetyNumberAci'
|
||||
} else if (mode === SafetyNumberMode.E164) {
|
||||
} else if (mode === SafetyNumberMode.JustE164) {
|
||||
identifierTypes = [SafetyNumberIdentifierType.E164Identifier];
|
||||
} else if (mode === SafetyNumberMode.DefaultACIAndMaybeE164) {
|
||||
identifierTypes = [
|
||||
SafetyNumberIdentifierType.ACIIdentifier,
|
||||
SafetyNumberIdentifierType.E164Identifier,
|
||||
];
|
||||
} else {
|
||||
assertDev(mode === SafetyNumberMode.ACI, 'Invalid security number mode');
|
||||
identifierTypes = [SafetyNumberIdentifierType.ACIIdentifier];
|
||||
throw missingCaseError(mode);
|
||||
}
|
||||
|
||||
return identifierTypes
|
||||
|
|
Loading…
Reference in a new issue