diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index d12987c82..ee8c6789a 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1356,9 +1356,28 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { completion:(void (^)(BOOL didConfirmIdentity))completionHandler { return [SafetyNumberConfirmationAlert presentAlertIfNecessaryWithRecipientIds:self.thread.recipientIdentifiers - confirmationText:confirmationText - contactsManager:self.contactsManager - completion:completionHandler]; + confirmationText:confirmationText + contactsManager:self.contactsManager + completion:^(BOOL didShowAlert) { + // Pre iOS-11, the keyboard and inputAccessoryView will obscure the alert if the keyboard is up when the + // alert is presented, so after hiding it, we regain first responder here. + if (@available(iOS 11.0, *)) { + // do nothing + } else { + [self becomeFirstResponder]; + } + completionHandler(didShowAlert); + } + beforePresentationHandler:^(void) { + if (@available(iOS 11.0, *)) { + // do nothing + } else { + // Pre iOS-11, the keyboard and inputAccessoryView will obscure the alert if the keyboard is up when the + // alert is presented. + [self dismissKeyBoard]; + [self resignFirstResponder]; + } + }]; } - (void)showFingerprintWithRecipientId:(NSString *)recipientId diff --git a/Signal/src/ViewControllers/SafetyNumberConfirmationAlert.swift b/Signal/src/ViewControllers/SafetyNumberConfirmationAlert.swift index e54bc12a1..b98a7d10b 100644 --- a/Signal/src/ViewControllers/SafetyNumberConfirmationAlert.swift +++ b/Signal/src/ViewControllers/SafetyNumberConfirmationAlert.swift @@ -18,13 +18,22 @@ class SafetyNumberConfirmationAlert: NSObject { } public class func presentAlertIfNecessary(recipientId: String, confirmationText: String, contactsManager: OWSContactsManager, completion: @escaping (Bool) -> Void) -> Bool { - return self.presentAlertIfNecessary(recipientIds: [recipientId], confirmationText: confirmationText, contactsManager: contactsManager, completion: completion) + return self.presentAlertIfNecessary(recipientIds: [recipientId], confirmationText: confirmationText, contactsManager: contactsManager, completion: completion, beforePresentationHandler: nil) + } + + public class func presentAlertIfNecessary(recipientId: String, confirmationText: String, contactsManager: OWSContactsManager, completion: @escaping (Bool) -> Void, beforePresentationHandler: (() -> Void)? = nil) -> Bool { + return self.presentAlertIfNecessary(recipientIds: [recipientId], confirmationText: confirmationText, contactsManager: contactsManager, completion: completion, beforePresentationHandler: beforePresentationHandler) } public class func presentAlertIfNecessary(recipientIds: [String], confirmationText: String, contactsManager: OWSContactsManager, completion: @escaping (Bool) -> Void) -> Bool { + return self.presentAlertIfNecessary(recipientIds: recipientIds, confirmationText: confirmationText, contactsManager: contactsManager, completion: completion, beforePresentationHandler: nil) + } + + public class func presentAlertIfNecessary(recipientIds: [String], confirmationText: String, contactsManager: OWSContactsManager, completion: @escaping (Bool) -> Void, beforePresentationHandler: (() -> Void)? = nil) -> Bool { return SafetyNumberConfirmationAlert(contactsManager: contactsManager).presentIfNecessary(recipientIds: recipientIds, confirmationText: confirmationText, - completion: completion) + completion: completion, + beforePresentationHandler: beforePresentationHandler) } /** @@ -33,7 +42,7 @@ class SafetyNumberConfirmationAlert: NSObject { * @returns true if an alert was shown * false if there were no unconfirmed identities */ - public func presentIfNecessary(recipientIds: [String], confirmationText: String, completion: @escaping (Bool) -> Void) -> Bool { + public func presentIfNecessary(recipientIds: [String], confirmationText: String, completion: @escaping (Bool) -> Void, beforePresentationHandler: (() -> Void)? = nil) -> Bool { guard let untrustedIdentity = untrustedIdentityForSending(recipientIds: recipientIds) else { // No identities to confirm, no alert to present. @@ -75,7 +84,15 @@ class SafetyNumberConfirmationAlert: NSObject { } actionSheetController.addAction(showSafetyNumberAction) - actionSheetController.addAction(OWSAlerts.cancelAction) + // We can't use the default `OWSAlerts.cancelAction` because we need to specify that the completion + // handler is called. + let cancelAction = UIAlertAction(title: CommonStrings.cancelButton, style: .cancel) { _ in + Logger.info("\(self.logTag) user canceled.") + completion(false) + } + actionSheetController.addAction(cancelAction) + + beforePresentationHandler?() UIApplication.shared.frontmostViewController?.present(actionSheetController, animated: true) return true diff --git a/Signal/src/call/OutboundCallInitiator.swift b/Signal/src/call/OutboundCallInitiator.swift index 051db267c..1d411ff45 100644 --- a/Signal/src/call/OutboundCallInitiator.swift +++ b/Signal/src/call/OutboundCallInitiator.swift @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // import Foundation @@ -55,11 +55,12 @@ import SignalMessaging let showedAlert = SafetyNumberConfirmationAlert.presentAlertIfNecessary(recipientId: recipientId, confirmationText: CallStrings.confirmAndCallButtonTitle, - contactsManager: self.contactsManager) { didConfirmIdentity in + contactsManager: self.contactsManager, + completion: { didConfirmIdentity in if didConfirmIdentity { _ = self.initiateCall(recipientId: recipientId) } - } + }) guard !showedAlert else { return false }