Added a loading state when approving a message request

Removed the 'presentTimer' logic from the 'ModalActivityIndicatorViewController' (the delay looked buggy, if it does have "blipping" issues then we can fix those separately)
pull/568/head
Morgan Pretty 3 years ago
parent f0f4128db2
commit 9251d98bde

@ -1146,18 +1146,31 @@ extension ConversationVC {
guard !contact.isApproved else { return Promise.value(()) }
return Promise.value(())
.then { _ -> Promise<Void> in
.then { [weak self] _ -> Promise<Void> 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<Void>.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

@ -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
}

Loading…
Cancel
Save