Extract region from e164 in FindByPhoneNumber

This commit is contained in:
Fedor Indutny 2024-02-13 12:10:12 -08:00 committed by GitHub
parent 1fee320d19
commit d7f0978c6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 12 deletions

View file

@ -127,7 +127,7 @@
"fs-extra": "5.0.0",
"fuse.js": "6.5.3",
"glob": "7.1.6",
"google-libphonenumber": "3.2.27",
"google-libphonenumber": "3.2.34",
"got": "11.8.5",
"heic-convert": "1.2.4",
"humanize-duration": "3.27.1",
@ -228,7 +228,7 @@
"@types/direction": "1.0.0",
"@types/filesize": "3.6.0",
"@types/fs-extra": "5.0.5",
"@types/google-libphonenumber": "7.4.23",
"@types/google-libphonenumber": "7.4.30",
"@types/history": "4.7.2",
"@types/humanize-duration": "3.18.1",
"@types/intl-tel-input": "17.0.4",

View file

@ -12,6 +12,7 @@ import {
values,
without,
} from 'lodash';
import type { PhoneNumber } from 'google-libphonenumber';
import { clipboard } from 'electron';
import type { ReadonlyDeep } from 'type-fest';
@ -27,6 +28,7 @@ import type { DurationInSeconds } from '../../util/durations';
import * as universalExpireTimer from '../../util/universalExpireTimer';
import * as Attachment from '../../types/Attachment';
import { isFileDangerous } from '../../util/isFileDangerous';
import { instance as libphonenumberInstance } from '../../util/libphonenumberInstance';
import type {
ShowSendAnywayDialogActionType,
ShowErrorModalActionType,
@ -6035,13 +6037,46 @@ export function reducer(
return state;
}
return {
const { searchTerm } = action.payload;
// Basic state that we return if we can't parse the term.
const withUpdatedSearchTerm = {
...state,
composer: {
...composer,
searchTerm: action.payload.searchTerm,
searchTerm,
},
};
if (composer.step === ComposerStep.FindByPhoneNumber) {
const { selectedRegion } = composer;
let result: PhoneNumber;
try {
result = libphonenumberInstance.parse(searchTerm, selectedRegion);
} catch {
return withUpdatedSearchTerm;
}
const region = libphonenumberInstance.getRegionCodeForNumber(result);
if (!result.hasCountryCode() || !region || region === selectedRegion) {
return withUpdatedSearchTerm;
}
result.clearCountryCode();
const withoutCountryCode =
libphonenumberInstance.formatInOriginalFormat(result);
return {
...state,
composer: {
...composer,
selectedRegion: region,
searchTerm: withoutCountryCode,
},
};
}
return withUpdatedSearchTerm;
}
if (action.type === 'SET_COMPOSE_SELECTED_REGION') {

View file

@ -5247,10 +5247,10 @@
"@types/minimatch" "*"
"@types/node" "*"
"@types/google-libphonenumber@7.4.23":
version "7.4.23"
resolved "https://registry.yarnpkg.com/@types/google-libphonenumber/-/google-libphonenumber-7.4.23.tgz#c44c9125d45f042943694d605fd8d8d796cafc3b"
integrity sha512-C3ydakLTQa8HxtYf9ge4q6uT9krDX8smSIxmmW3oACFi5g5vv6T068PRExF7UyWbWpuYiDG8Nm24q2X5XhcZWw==
"@types/google-libphonenumber@7.4.30":
version "7.4.30"
resolved "https://registry.yarnpkg.com/@types/google-libphonenumber/-/google-libphonenumber-7.4.30.tgz#a47ed8f1f237bd43edbd1c8aff24400b0fd9b2fe"
integrity sha512-Td1X1ayRxePEm6/jPHUBs2tT6TzW1lrVB6ZX7ViPGellyzO/0xMNi+wx5nH6jEitjznq276VGIqjK5qAju0XVw==
"@types/graceful-fs@^4.1.3":
version "4.1.7"
@ -11072,10 +11072,10 @@ globjoin@^0.1.4:
resolved "https://registry.yarnpkg.com/globjoin/-/globjoin-0.1.4.tgz#2f4494ac8919e3767c5cbb691e9f463324285d43"
integrity sha512-xYfnw62CKG8nLkZBfWbhWwDw02CHty86jfPcc2cr3ZfeuK9ysoVPPEUxf21bAD/rWAgk52SuBrLJlefNy8mvFg==
google-libphonenumber@3.2.27:
version "3.2.27"
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.27.tgz#06a0c1d42be712a6fd4189e2e3b07fc36cacee01"
integrity sha512-et3QlrfWemNPhyUfXZmJG8TfzitfAN71ygNI15+B35zNge/7vyZxkpDsc13oninkf8RAtN2kNEzvMr4L1n3vfQ==
google-libphonenumber@3.2.34:
version "3.2.34"
resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.34.tgz#ef29b53be0f9fb517aaa53d26a541150f86ec921"
integrity sha512-CLwkp0lZvMywh6dCh0T3Fm8XsfJhLAupc8AECwYkJNQBPW8wQPrv/tV0oFKCs8FMw+pTQyNPZoycgBzYjqtTZQ==
gopd@^1.0.1:
version "1.0.1"