WIP: fix call from contacts when signal hasn't been launched yet

This commit is contained in:
Michael Kirk 2017-06-20 16:13:16 -04:00
parent 59d3e9ed51
commit ff93732ed7
7 changed files with 81 additions and 75 deletions

View File

@ -22,6 +22,7 @@
#import "PropertyListPreferences.h"
#import "PushManager.h"
#import "SettingsTableViewController.h"
#import "SignalsViewController.h"
#import "UIColor+OWS.h"
#import "UIFont+OWS.h"
#import "UIUtil.h"

View File

@ -95,7 +95,6 @@
<outlet property="hideMissingContactsPermissionViewConstraint" destination="b7U-Ma-c6S" id="bcT-sh-weS"/>
<outlet property="missingContactsPermissionView" destination="7iZ-hQ-Iik" id="aWf-NH-kn6"/>
<outlet property="tableView" destination="PaA-ol-uQT" id="nQU-tR-wbL"/>
<segue destination="Tyf-mN-gzf" kind="modal" identifier="ShowIncomingCallSegue" id="G2B-Fr-Ezs"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dE8-zB-mtF" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -150,23 +149,6 @@
</objects>
<point key="canvasLocation" x="-2287" y="-1516"/>
</scene>
<!--New Call-->
<scene sceneID="Xck-Ph-UlV">
<objects>
<viewController storyboardIdentifier="OWSCallViewController" title="New Call" definesPresentationContext="YES" modalTransitionStyle="crossDissolve" modalPresentationStyle="currentContext" id="Tyf-mN-gzf" customClass="OWSCallViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="0w2-kv-AfM"/>
<viewControllerLayoutGuide type="bottom" id="d8M-LU-Hfa"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="fjB-Ns-OQs">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="5mi-rT-gg5" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1790" y="-2348"/>
</scene>
<!--Signals Navigation Controller-->
<scene sceneID="miN-Ma-3eR">
<objects>

View File

@ -8,7 +8,6 @@ import PromiseKit
// TODO: Add category so that button handlers can be defined where button is created.
// TODO: Ensure buttons enabled & disabled as necessary.
@objc(OWSCallViewController)
class CallViewController: UIViewController, CallObserver, CallServiceObserver, RTCEAGLVideoViewDelegate {
let TAG = "[CallViewController]"

View File

@ -31,7 +31,7 @@
#define CELL_HEIGHT 72.0f
#define HEADER_HEIGHT 44.0f
NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallSegue";
// NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallSegue";
@interface SignalsViewController ()
@ -195,12 +195,12 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS
(self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)) {
[self registerForPreviewingWithDelegate:self sourceView:self.tableView];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleActiveCallNotification:)
name:[CallService callServiceActiveCallNotificationName]
object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(handleActiveCallNotification:)
// name:[CallService callServiceActiveCallNotificationName]
// object:nil];
//
[self updateBarButtonItems];
}
@ -260,29 +260,30 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS
}
}
- (void)handleActiveCallNotification:(NSNotification *)notification
{
AssertIsOnMainThread();
if (![notification.object isKindOfClass:[SignalCall class]]) {
DDLogError(@"%@ expected presentCall observer to be notified with a SignalCall, but found %@",
self.tag,
notification.object);
return;
}
SignalCall *call = (SignalCall *)notification.object;
// Dismiss any other modals so we can present call modal.
if (self.presentedViewController) {
[self dismissViewControllerAnimated:YES
completion:^{
[self performSegueWithIdentifier:SignalsViewControllerSegueShowIncomingCall sender:call];
}];
} else {
[self performSegueWithIdentifier:SignalsViewControllerSegueShowIncomingCall sender:call];
}
}
//- (void)handleActiveCallNotification:(NSNotification *)notification
//{
// // TODO insteead at the callsite lets present as topmost VC
// AssertIsOnMainThread();
//
// if (![notification.object isKindOfClass:[SignalCall class]]) {
// DDLogError(@"%@ expected presentCall observer to be notified with a SignalCall, but found %@",
// self.tag,
// notification.object);
// return;
// }
//
// SignalCall *call = (SignalCall *)notification.object;
//
// // Dismiss any other modals so we can present call modal.
// if (self.presentedViewController) {
// [self dismissViewControllerAnimated:YES
// completion:^{
// [self performSegueWithIdentifier:SignalsViewControllerSegueShowIncomingCall sender:call];
// }];
// } else {
// [self performSegueWithIdentifier:SignalsViewControllerSegueShowIncomingCall sender:call];
// }
//}
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext
commitViewController:(UIViewController *)viewControllerToCommit {
@ -727,25 +728,25 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:SignalsViewControllerSegueShowIncomingCall]) {
DDLogDebug(@"%@ preparing for incoming call segue", self.tag);
if (![segue.destinationViewController isKindOfClass:[OWSCallViewController class]]) {
DDLogError(@"%@ Received unexpected destination view controller: %@", self.tag, segue.destinationViewController);
return;
}
OWSCallViewController *callViewController = (OWSCallViewController *)segue.destinationViewController;
if (![sender isKindOfClass:[SignalCall class]]) {
DDLogError(@"%@ expecting call segueu to be sent by a SignalCall, but found: %@", self.tag, sender);
return;
}
SignalCall *call = (SignalCall *)sender;
TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:call.remotePhoneNumber];
callViewController.thread = thread;
callViewController.call = call;
}
}
//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// if ([segue.identifier isEqualToString:SignalsViewControllerSegueShowIncomingCall]) {
// DDLogDebug(@"%@ preparing for incoming call segue", self.tag);
// if (![segue.destinationViewController isKindOfClass:[OWSCallViewController class]]) {
// DDLogError(@"%@ Received unexpected destination view controller: %@", self.tag,
// segue.destinationViewController); return;
// }
// OWSCallViewController *callViewController = (OWSCallViewController *)segue.destinationViewController;
//
// if (![sender isKindOfClass:[SignalCall class]]) {
// DDLogError(@"%@ expecting call segueu to be sent by a SignalCall, but found: %@", self.tag, sender);
// return;
// }
// SignalCall *call = (SignalCall *)sender;
// TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:call.remotePhoneNumber];
// callViewController.thread = thread;
// callViewController.call = call;
// }
//}
#pragma mark - IBAction

View File

@ -253,9 +253,9 @@ protocol CallServiceObserver: class {
// MARK: Notifications
// Wrapping these class constants in a method to make it accessible to objc
class func callServiceActiveCallNotificationName() -> String {
return "CallServiceActiveCallNotification"
}
// class func callServiceActiveCallNotificationName() -> String {
// return "CallServiceActiveCallNotification"
// }
// MARK: - Service Actions

View File

@ -42,8 +42,9 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
Logger.debug("\(TAG) \(#function)")
// present Call View controller
let callNotificationName = CallService.callServiceActiveCallNotificationName()
NotificationCenter.default.post(name: NSNotification.Name(rawValue: callNotificationName), object: call)
// let callNotificationName = CallService.callServiceActiveCallNotificationName()
// NotificationCenter.default.post(name: NSNotification.Name(rawValue: callNotificationName), object: call)
self.showCall(call)
// present lock screen notification
if UIApplication.shared.applicationState == .active {

View File

@ -34,8 +34,30 @@ extension CallUIAdaptee {
internal func showCall(_ call: SignalCall) {
AssertIsOnMainThread()
let callNotificationName = CallService.callServiceActiveCallNotificationName()
NotificationCenter.default.post(name: NSNotification.Name(rawValue: callNotificationName), object: call)
// let callNotificationName = CallService.callServiceActiveCallNotificationName()
// NotificationCenter.default.post(name: NSNotification.Name(rawValue: callNotificationName), object: call)
let callViewController = CallViewController()
let thread = TSContactThread.getOrCreateThread(contactId: call.remotePhoneNumber)
callViewController.call = call
callViewController.thread = thread
callViewController.modalTransitionStyle = .crossDissolve
//Environment.getCurrent().signalsViewController
// TODO dismiss any modal, can/should we present from frontmost?
// let presentingViewController = UIApplication.shared.frontmostViewController
// presentingViewController?.present(callViewController, animated: true)
guard let presentingViewController = Environment.getCurrent().signalsViewController else {
Logger.error("in \(#function) signals view controller unexpectedly nil")
assertionFailure("in \(#function) signals view controller unexpectedly nil")
return
}
if let presentedViewController = presentingViewController.presentedViewController {
presentedViewController.dismiss(animated: false)
}
presentingViewController.present(callViewController, animated: true)
}
internal func reportMissedCall(_ call: SignalCall, callerName: String) {