mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Phased rollout by country code; starting w/ desktop.stories remote flag
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
import memoizee from 'memoizee';
|
||||
import { instance, PhoneNumberFormat } from '../util/libphonenumberInstance';
|
||||
import * as log from '../logging/log';
|
||||
import * as Errors from './errors';
|
||||
|
||||
function _format(
|
||||
phoneNumber: string,
|
||||
@@ -25,6 +27,27 @@ function _format(
|
||||
}
|
||||
}
|
||||
|
||||
export function getCountryCode(
|
||||
phoneNumber: string | undefined
|
||||
): number | undefined {
|
||||
try {
|
||||
if (phoneNumber == null) {
|
||||
return undefined;
|
||||
}
|
||||
if (!isValidNumber(phoneNumber)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return instance.parse(phoneNumber).getCountryCode();
|
||||
} catch (error) {
|
||||
const errorText = Errors.toLogFormat(error);
|
||||
log.info(
|
||||
`getCountryCode: Failed to get country code from ${phoneNumber}: ${errorText}`
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function isValidNumber(
|
||||
phoneNumber: string,
|
||||
options?: {
|
||||
|
||||
Reference in New Issue
Block a user