convert to guard statements for readability

pull/1/head
Michael Kirk 7 years ago committed by Matthew Chen
parent ea76ea9492
commit 5d9e03ba40

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

Loading…
Cancel
Save