share global callUIAdapter, outboundCallInitiator

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent bbfd9ba74d
commit 17b89f44aa

@ -342,7 +342,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
DDLogInfo(@"%@ got start audio call intent", self.tag); DDLogInfo(@"%@ got start audio call intent", self.tag);
// hoooooooooooly moly.
INInteraction *interaction = [userActivity interaction]; INInteraction *interaction = [userActivity interaction];
INIntent *intent = interaction.intent; INIntent *intent = interaction.intent;
@ -357,23 +356,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return NO; return NO;
} }
CallUIAdapter *callUIAdapter = [Environment getCurrent].callService.callUIAdapter; OutboundCallInitiator *outboundCallInitiator = [Environment getCurrent].outboundCallInitiator;
OWSAssert(callUIAdapter); OWSAssert(outboundCallInitiator);
ContactsUpdater *contactsUpdater = [Environment getCurrent].contactsUpdater;
OWSAssert(contactsUpdater);
OWSContactsManager *contactsManager = [Environment getCurrent].contactsManager;
OWSAssert(contactsManager);
PhoneManager *phoneManager = [Environment getCurrent].phoneManager;
OWSAssert(phoneManager);
OutboundCallInitiator *outboundCallInitiator =
[[OutboundCallInitiator alloc] initWithRedphoneManager:phoneManager
callUIAdapter:callUIAdapter
contactsManager:contactsManager
contactsUpdater:contactsUpdater];
return [outboundCallInitiator initiateCallWithHandle:handle]; return [outboundCallInitiator initiateCallWithHandle:handle];
} else { } else {
DDLogWarn(@"%@ called %s with userActivity: %@, but not yet supported.", DDLogWarn(@"%@ called %s with userActivity: %@, but not yet supported.",

@ -31,6 +31,7 @@ static NSString *const kRedphoneCallSegue = @"2.0_6.0_Call_Segue";
@class UINavigationController; @class UINavigationController;
@class RecentCallManager; @class RecentCallManager;
@class OWSContactsManager; @class OWSContactsManager;
@class OutboundCallInitiator;
@class PhoneManager; @class PhoneManager;
@class SignalsViewController; @class SignalsViewController;
@class TSGroupThread; @class TSGroupThread;
@ -38,6 +39,7 @@ static NSString *const kRedphoneCallSegue = @"2.0_6.0_Call_Segue";
@class TSNetworkManager; @class TSNetworkManager;
@class AccountManager; @class AccountManager;
@class OWSWebRTCCallMessageHandler; @class OWSWebRTCCallMessageHandler;
@class CallUIAdapter;
@class CallService; @class CallService;
@class OWSMessageSender; @class OWSMessageSender;
@class NotificationsManager; @class NotificationsManager;
@ -78,8 +80,10 @@ static NSString *const kRedphoneCallSegue = @"2.0_6.0_Call_Segue";
@property (nonatomic, readonly) NSData *zrtpVersionId; @property (nonatomic, readonly) NSData *zrtpVersionId;
@property (nonatomic, readonly) AccountManager *accountManager; @property (nonatomic, readonly) AccountManager *accountManager;
@property (nonatomic, readonly) OWSWebRTCCallMessageHandler *callMessageHandler; @property (nonatomic, readonly) OWSWebRTCCallMessageHandler *callMessageHandler;
@property (nonatomic, readonly) CallUIAdapter *callUIAdapter;
@property (nonatomic, readonly) CallService *callService; @property (nonatomic, readonly) CallService *callService;
@property (nonatomic, readonly) OWSContactsManager *contactsManager; @property (nonatomic, readonly) OWSContactsManager *contactsManager;
@property (nonatomic, readonly) OutboundCallInitiator *outboundCallInitiator;
@property (nonatomic, readonly) ContactsUpdater *contactsUpdater; @property (nonatomic, readonly) ContactsUpdater *contactsUpdater;
@property (nonatomic, readonly) TSNetworkManager *networkManager; @property (nonatomic, readonly) TSNetworkManager *networkManager;
@property (nonatomic, readonly) NotificationsManager *notificationsManager; @property (nonatomic, readonly) NotificationsManager *notificationsManager;

@ -23,11 +23,12 @@ static Environment *environment = nil;
@implementation Environment @implementation Environment
@synthesize accountManager = _accountManager; @synthesize accountManager = _accountManager,
@synthesize callMessageHandler = _callMessageHandler; callMessageHandler = _callMessageHandler,
@synthesize callService = _callService; callService = _callService,
@synthesize notificationsManager = _notificationsManager; notificationsManager = _notificationsManager,
@synthesize preferences = _preferences; preferences = _preferences,
outboundCallInitiator = _outboundCallInitiator;
+ (Environment *)getCurrent { + (Environment *)getCurrent {
NSAssert((environment != nil), @"Environment is not defined."); NSAssert((environment != nil), @"Environment is not defined.");
@ -159,6 +160,9 @@ static Environment *environment = nil;
{ {
@synchronized (self) { @synchronized (self) {
if (!_callService) { if (!_callService) {
OWSAssert(self.accountManager);
OWSAssert(self.contactsManager);
OWSAssert(self.messageSender);
_callService = [[CallService alloc] initWithAccountManager:self.accountManager _callService = [[CallService alloc] initWithAccountManager:self.accountManager
contactsManager:self.contactsManager contactsManager:self.contactsManager
messageSender:self.messageSender messageSender:self.messageSender
@ -169,6 +173,29 @@ static Environment *environment = nil;
return _callService; return _callService;
} }
- (CallUIAdapter *)callUIAdapter
{
return self.callService.callUIAdapter;
}
- (OutboundCallInitiator *)outboundCallInitiator
{
@synchronized (self) {
if (!_outboundCallInitiator) {
OWSAssert(self.phoneManager);
OWSAssert(self.callUIAdapter);
OWSAssert(self.contactsManager);
OWSAssert(self.contactsUpdater);
_outboundCallInitiator = [[OutboundCallInitiator alloc] initWithRedphoneManager:self.phoneManager
callUIAdapter:self.callUIAdapter
contactsManager:self.contactsManager
contactsUpdater:self.contactsUpdater];
}
}
return _outboundCallInitiator;
}
+ (PhoneManager *)phoneManager { + (PhoneManager *)phoneManager {
return Environment.getCurrent.phoneManager; return Environment.getCurrent.phoneManager;
} }

@ -83,15 +83,13 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
contactsManager = Environment.getCurrent().contactsManager contactsManager = Environment.getCurrent().contactsManager
let callService = Environment.getCurrent().callService! callUIAdapter = Environment.getCurrent().callUIAdapter
callUIAdapter = callService.callUIAdapter
super.init(coder: aDecoder) super.init(coder: aDecoder)
} }
required init() { required init() {
contactsManager = Environment.getCurrent().contactsManager contactsManager = Environment.getCurrent().contactsManager
let callService = Environment.getCurrent().callService! callUIAdapter = Environment.getCurrent().callUIAdapter
callUIAdapter = callService.callUIAdapter
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
} }

@ -125,6 +125,7 @@ typedef enum : NSUInteger {
@property (nonatomic, readonly) OWSDisappearingMessagesJob *disappearingMessagesJob; @property (nonatomic, readonly) OWSDisappearingMessagesJob *disappearingMessagesJob;
@property (nonatomic, readonly) TSMessagesManager *messagesManager; @property (nonatomic, readonly) TSMessagesManager *messagesManager;
@property (nonatomic, readonly) TSNetworkManager *networkManager; @property (nonatomic, readonly) TSNetworkManager *networkManager;
@property (nonatomic, readonly) OutboundCallInitiator *outboundCallInitiator;
@property NSCache *messageAdapterCache; @property NSCache *messageAdapterCache;
@ -166,6 +167,7 @@ typedef enum : NSUInteger {
_contactsManager = [Environment getCurrent].contactsManager; _contactsManager = [Environment getCurrent].contactsManager;
_contactsUpdater = [Environment getCurrent].contactsUpdater; _contactsUpdater = [Environment getCurrent].contactsUpdater;
_messageSender = [Environment getCurrent].messageSender; _messageSender = [Environment getCurrent].messageSender;
_outboundCallInitiator = [Environment getCurrent].outboundCallInitiator;
_storageManager = [TSStorageManager sharedManager]; _storageManager = [TSStorageManager sharedManager];
_disappearingMessagesJob = [[OWSDisappearingMessagesJob alloc] initWithStorageManager:_storageManager]; _disappearingMessagesJob = [[OWSDisappearingMessagesJob alloc] initWithStorageManager:_storageManager];
_messagesManager = [TSMessagesManager sharedManager]; _messagesManager = [TSMessagesManager sharedManager];
@ -631,54 +633,7 @@ typedef enum : NSUInteger {
return; return;
} }
// Since users can toggle this setting, which is only communicated during contact sync, it's easy to imagine the [self.outboundCallInitiator initiateCallWithRecipientId:self.thread.contactIdentifier];
// preference getting stale. Especially as users are toggling the feature to test calls. So here, we opt for a
// blocking network request *every* time we place a call to make sure we've got up to date preferences.
//
// e.g. The following would suffice if we weren't worried about stale preferences.
// SignalRecipient *recipient = [SignalRecipient recipientWithTextSecureIdentifier:self.thread.contactIdentifier];
BOOL localWantsWebRTC = [Environment preferences].isWebRTCEnabled;
if (!localWantsWebRTC) {
[self placeRedphoneCall];
return;
}
[self.contactsUpdater lookupIdentifier:self.thread.contactIdentifier
success:^(SignalRecipient *_Nonnull recipient) {
BOOL remoteWantsWebRTC = recipient.supportsWebRTC;
DDLogDebug(@"%@ localWantsWebRTC?: %@, remoteWantsWebRTC?: %@",
self.tag,
(localWantsWebRTC ? @"YES" : @"NO"),
(remoteWantsWebRTC ? @"YES" : @"NO"));
if (localWantsWebRTC && remoteWantsWebRTC) {
[self placeWebRTCCall];
} else {
[self placeRedphoneCall];
}
}
failure:^(NSError *_Nonnull error) {
DDLogWarn(@"%@ looking up call recipient: %@ failed with error: %@", self.tag, self.thread, error);
SignalAlertView(NSLocalizedString(@"UNABLE_TO_PLACE_CALL", @"Alert Title"), error.localizedDescription);
}];
}
- (void)placeRedphoneCall
{
DDLogInfo(@"%@ Placing redphone call to: %@", self.tag, self.thread);
PhoneNumber *number = [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:self.thread.contactIdentifier];
Contact *contact = [self.contactsManager latestContactForPhoneNumber:number];
OWSAssert(number != nil);
OWSAssert(contact != nil);
[Environment.phoneManager initiateOutgoingCallToContact:contact atRemoteNumber:number];
}
- (void)placeWebRTCCall
{
DDLogInfo(@"%@ Placing WebRTC call to: %@", self.tag, self.thread);
[self performSegueWithIdentifier:OWSMessagesViewControllerSegueInitiateCall sender:self];
} }
- (BOOL)canCall { - (BOOL)canCall {

Loading…
Cancel
Save