From 85d58d3396ef92400d34b2a0892a96a06147992a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 21 Mar 2019 14:48:23 -0400 Subject: [PATCH] Improve handling of call intents. --- Signal/src/AppDelegate.m | 43 +++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index a6b4afeed..c626266ba 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -852,13 +852,10 @@ static NSTimeInterval launchStartedAt; return; } - NSString *_Nullable phoneNumber = handle; - if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) { - phoneNumber = [self.primaryStorage phoneNumberForCallKitId:handle]; - if (phoneNumber.length < 1) { - OWSLogWarn(@"ignoring attempt to initiate video call to unknown anonymous signal user."); - return; - } + NSString *_Nullable phoneNumber = [self phoneNumberForIntentHandle:handle]; + if (phoneNumber.length < 1) { + OWSLogWarn(@"ignoring attempt to initiate video call to unknown user."); + return; } // This intent can be received from more than one user interaction. @@ -914,13 +911,10 @@ static NSTimeInterval launchStartedAt; return; } - NSString *_Nullable phoneNumber = handle; - if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) { - phoneNumber = [self.primaryStorage phoneNumberForCallKitId:handle]; - if (phoneNumber.length < 1) { - OWSLogWarn(@"ignoring attempt to initiate audio call to unknown anonymous signal user."); - return; - } + NSString *_Nullable phoneNumber = [self phoneNumberForIntentHandle:handle]; + if (phoneNumber.length < 1) { + OWSLogWarn(@"ignoring attempt to initiate audio call to unknown user."); + return; } if (AppEnvironment.shared.callService.call != nil) { @@ -962,6 +956,27 @@ static NSTimeInterval launchStartedAt; return NO; } +- (nullable NSString *)phoneNumberForIntentHandle:(NSString *)handle +{ + OWSAssertDebug(handle.length > 0); + + if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) { + NSString *_Nullable phoneNumber = [self.primaryStorage phoneNumberForCallKitId:handle]; + if (phoneNumber.length < 1) { + OWSLogWarn(@"ignoring attempt to initiate audio call to unknown anonymous signal user."); + return nil; + } + return phoneNumber; + } + + for (PhoneNumber *phoneNumber in + [PhoneNumber tryParsePhoneNumbersFromsUserSpecifiedText:handle + clientPhoneNumber:[TSAccountManager localNumber]]) { + return phoneNumber.toE164; + } + return nil; +} + #pragma mark - Orientation - (UIInterfaceOrientationMask)application:(UIApplication *)application