From 5856e351aebb32d25aacc108f721cdd69a94f6d1 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 25 Jan 2017 11:41:30 -0500 Subject: [PATCH] Respect WebRTC calling preference (#1640) TODO: this is going to be weird when two parties are *just* enabling webrtc for the first time. We might want to do something as drastic as refetch contact information before completing the call. // FREEBIE --- .../view controllers/MessagesViewController.m | 43 ++++++------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/Signal/src/view controllers/MessagesViewController.m b/Signal/src/view controllers/MessagesViewController.m index 43432bccc..278344bd0 100644 --- a/Signal/src/view controllers/MessagesViewController.m +++ b/Signal/src/view controllers/MessagesViewController.m @@ -66,21 +66,6 @@ @import Photos; -@interface Contact (redphoneStubbing) - -@property (nonatomic, readonly) BOOL prefersRedphoneContact; - -@end - -@implementation Contact (redphoneStubbing) - -- (BOOL)prefersRedphoneContact -{ - return NO; -} - -@end - #define kYapDatabaseRangeLength 50 #define kYapDatabaseRangeMaxLength 300 #define kYapDatabaseRangeMinLength 20 @@ -641,32 +626,28 @@ typedef enum : NSUInteger { #pragma mark - Calls -- (SignalRecipient *)signalRecipient { - __block SignalRecipient *recipient; - [self.editingDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - recipient = [SignalRecipient recipientWithTextSecureIdentifier:[self phoneNumberForThread].toE164 - withTransaction:transaction]; - }]; - return recipient; -} - -- (BOOL)isTextSecureReachable { - return isGroupConversation || [self signalRecipient]; -} - - (PhoneNumber *)phoneNumberForThread { NSString *contactId = [(TSContactThread *)self.thread contactIdentifier]; return [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:contactId]; } - (void)callAction { + OWSAssert([self.thread isKindOfClass:[TSContactThread class]]); + if ([self canCall]) { PhoneNumber *number = [self phoneNumberForThread]; Contact *contact = [self.contactsManager latestContactForPhoneNumber:number]; - if (contact.prefersRedphoneContact) { - [Environment.phoneManager initiateOutgoingCallToContact:contact atRemoteNumber:number]; - } else { + SignalRecipient *recipient = [SignalRecipient recipientWithTextSecureIdentifier:self.thread.contactIdentifier]; + + BOOL localWantsWebRTC = [Environment preferences].isWebRTCEnabled; + BOOL remoteWantsWebRTC = recipient.supportsWebRTC; + DDLogDebug(@"%@ localWantsWebRTC?: %@, remoteWantsWebRTC?: %@", self.tag, (localWantsWebRTC ? @"YES": @"NO"), (remoteWantsWebRTC ? @"YES" : @"NO")); + if (localWantsWebRTC && remoteWantsWebRTC) { + // Place WebRTC Call [self performSegueWithIdentifier:OWSMessagesViewControllerSegueInitiateCall sender:self]; + } else { + // Place Redphone call if either local or remote party has not opted in to WebRTC calling. + [Environment.phoneManager initiateOutgoingCallToContact:contact atRemoteNumber:number]; } } else { DDLogWarn(@"Tried to initiate a call but thread is not callable.");