|
|
|
|
@ -324,35 +324,38 @@ static NSString *const RPDefaultsKeyPhoneNumberCanonical = @"RPDefaultsKeyPhoneN
|
|
|
|
|
|
|
|
|
|
// Order matters; better results should appear first so prefer
|
|
|
|
|
// matches with the same country code as this client's phone number.
|
|
|
|
|
OWSAssertDebug(clientPhoneNumber.length > 0);
|
|
|
|
|
if (clientPhoneNumber.length > 0) {
|
|
|
|
|
// Note that NBPhoneNumber uses "country code" to refer to what we call a
|
|
|
|
|
// "calling code" (i.e. 44 in +44123123). Within SSK we use "country code"
|
|
|
|
|
// (and sometimes "region code") to refer to a country's ISO 2-letter code
|
|
|
|
|
// (ISO 3166-1 alpha-2).
|
|
|
|
|
NSNumber *callingCodeForLocalNumber = [[PhoneNumber phoneNumberFromE164:clientPhoneNumber] getCountryCode];
|
|
|
|
|
if (callingCodeForLocalNumber != nil) {
|
|
|
|
|
NSString *callingCodePrefix = [NSString stringWithFormat:@"+%@", callingCodeForLocalNumber];
|
|
|
|
|
|
|
|
|
|
tryParsingWithCountryCode(
|
|
|
|
|
[callingCodePrefix stringByAppendingString:sanitizedString], [self defaultCountryCode]);
|
|
|
|
|
|
|
|
|
|
// Try to determine what the country code is for the local phone number
|
|
|
|
|
// and also try parsing the phone number using that country code if it
|
|
|
|
|
// differs from the device's region code.
|
|
|
|
|
//
|
|
|
|
|
// For example, a French person living in Italy might have an
|
|
|
|
|
// Italian phone number but use French region/language for their
|
|
|
|
|
// phone. They're likely to have both Italian and French contacts.
|
|
|
|
|
NSString *localCountryCode =
|
|
|
|
|
[PhoneNumberUtil.sharedThreadLocal probableCountryCodeForCallingCode:callingCodePrefix];
|
|
|
|
|
if (localCountryCode && ![localCountryCode isEqualToString:[self defaultCountryCode]]) {
|
|
|
|
|
tryParsingWithCountryCode(
|
|
|
|
|
[callingCodePrefix stringByAppendingString:sanitizedString], localCountryCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (clientPhoneNumber.length == 0) {
|
|
|
|
|
OWSFailDebug(@"clientPhoneNumber had unexpected length");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Note that NBPhoneNumber uses "country code" to refer to what we call a
|
|
|
|
|
// "calling code" (i.e. 44 in +44123123). Within SSK we use "country code"
|
|
|
|
|
// (and sometimes "region code") to refer to a country's ISO 2-letter code
|
|
|
|
|
// (ISO 3166-1 alpha-2).
|
|
|
|
|
NSNumber *callingCodeForLocalNumber = [[PhoneNumber phoneNumberFromE164:clientPhoneNumber] getCountryCode];
|
|
|
|
|
if (callingCodeForLocalNumber == nil) {
|
|
|
|
|
OWSFailDebug(@"callingCodeForLocalNumber was unexpectedly nil");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString *callingCodePrefix = [NSString stringWithFormat:@"+%@", callingCodeForLocalNumber];
|
|
|
|
|
|
|
|
|
|
tryParsingWithCountryCode([callingCodePrefix stringByAppendingString:sanitizedString], [self defaultCountryCode]);
|
|
|
|
|
|
|
|
|
|
// Try to determine what the country code is for the local phone number
|
|
|
|
|
// and also try parsing the phone number using that country code if it
|
|
|
|
|
// differs from the device's region code.
|
|
|
|
|
//
|
|
|
|
|
// For example, a French person living in Italy might have an
|
|
|
|
|
// Italian phone number but use French region/language for their
|
|
|
|
|
// phone. They're likely to have both Italian and French contacts.
|
|
|
|
|
NSString *localCountryCode =
|
|
|
|
|
[PhoneNumberUtil.sharedThreadLocal probableCountryCodeForCallingCode:callingCodePrefix];
|
|
|
|
|
if (localCountryCode && ![localCountryCode isEqualToString:[self defaultCountryCode]]) {
|
|
|
|
|
tryParsingWithCountryCode([callingCodePrefix stringByAppendingString:sanitizedString], localCountryCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|