diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index dbd3859ac..8dd7cef14 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1146,18 +1146,31 @@ extension ConversationVC { guard !contact.isApproved else { return Promise.value(()) } return Promise.value(()) - .then { _ -> Promise in + .then { [weak self] _ -> Promise in guard !isNewThread else { return Promise.value(()) } + guard let strongSelf = self else { return Promise(error: MessageSender.Error.noThread) } // If we aren't creating a new thread (ie. sending a message request) then send a // messageRequestResponse back to the sender (this allows the sender to know that // they have been approved and can now use this contact in closed groups) + let (promise, seal) = Promise.pending() let messageRequestResponse: MessageRequestResponse = MessageRequestResponse( isApproved: true ) messageRequestResponse.sentTimestamp = timestamp - return MessageSender.sendNonDurably(messageRequestResponse, in: contactThread, using: transaction) + // Show a loading indicator + ModalActivityIndicatorViewController.present(fromViewController: strongSelf, canCancel: false) { _ in + seal.fulfill(()) + } + + return promise + .then { MessageSender.sendNonDurably(messageRequestResponse, in: contactThread, using: transaction) } + .map { _ in + if self?.presentedViewController is ModalActivityIndicatorViewController { + self?.dismiss(animated: true, completion: nil) // Dismiss the loader + } + } } .map { _ in // Default 'didApproveMe' to true for the person approving the message request diff --git a/SignalUtilitiesKit/Shared View Controllers/ModalActivityIndicatorViewController.swift b/SignalUtilitiesKit/Shared View Controllers/ModalActivityIndicatorViewController.swift index c99a28310..a38915a40 100644 --- a/SignalUtilitiesKit/Shared View Controllers/ModalActivityIndicatorViewController.swift +++ b/SignalUtilitiesKit/Shared View Controllers/ModalActivityIndicatorViewController.swift @@ -25,8 +25,6 @@ public class ModalActivityIndicatorViewController: OWSViewController { return result }() - var presentTimer: Timer? - var wasDimissed: Bool = false // MARK: Initializers @@ -127,41 +125,7 @@ public class ModalActivityIndicatorViewController: OWSViewController { self.spinner.startAnimating() - // Hide the the modal and wait for a second before revealing it, - // to avoid "blipping" in the modal during short blocking operations. - // - // NOTE: It will still intercept user interactions while hidden, as it - // should. - let kPresentationDelaySeconds = TimeInterval(1) - self.presentTimer?.invalidate() - self.presentTimer = Timer.weakScheduledTimer(withTimeInterval: kPresentationDelaySeconds, target: self, selector: #selector(presentTimerFired), userInfo: nil, repeats: false) - } - - public override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) - - clearTimer() - } - - public override func viewDidDisappear(_ animated: Bool) { - super.viewDidDisappear(animated) - - self.spinner.stopAnimating() - - clearTimer() - } - - private func clearTimer() { - self.presentTimer?.invalidate() - self.presentTimer = nil - } - - @objc func presentTimerFired() { - AssertIsOnMainThread() - - clearTimer() - - // Fade in the modal. + // Fade in the modal UIView.animate(withDuration: 0.35) { self.view.layer.opacity = 1.0 }