Skip to content

Commit

Permalink
INBIOS-76 Fix sending from the Share extension while offline
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekkra committed Jul 31, 2024
1 parent 00b6cc2 commit 71e78f7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,8 @@ enum L10n {
static let senderChanged = NSLocalizedString("Sender changed", comment: "Alert title, shows when current sender address in the composer is invalid anymore.")
static let senderChangedMessage = NSLocalizedString("The original sender of this message is no longer valid. Your message will be sent from your default address %@.", comment: "Alert message, shows when current sender address in the composer is invalid anymore, the placeholder is a mail address.")
static let blockSenderChangeMessage = NSLocalizedString("Please retry after all attachments are uploaded.", comment: "The alert message that will be shown when user tries to change the sender if there is any attachment being uploaded.")
static let sendingWithShareExtensionWhileOfflineIsNotSupported = NSLocalizedString("Sending with the Share extension while offline is not supported", comment: "Alert title")
static let messageSavedAsDraft = NSLocalizedString("Your message has been saved as a draft.", comment: "Alert message")
}

struct ContactEdit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import WebKit
/// HtmlEditorBehavior only adds some functionality to HorizontallyScrollableWebViewContainer's webView, is not a UIView or webView's delegate any more. ComposeViewController is tightly coupled with ComposeHeaderViewController and needs separate refactor, while ContainableComposeViewController and HorizontallyScrollableWebViewContainer contain absolute minimum of logic they need: logic allowing to embed composer into tableView cell and logic allowing 2D scroll in fullsize webView.
///
class ContainableComposeViewController: ComposeContentViewController, BannerRequester {
typealias Dependencies = ComposeContentViewController.Dependencies & HasKeyMakerProtocol
typealias Dependencies = ComposeContentViewController.Dependencies
& HasInternetConnectionStatusProviderProtocol
& HasKeyMakerProtocol
& HasQueueManager

private let dependencies: Dependencies
private var latestErrorBanner: BannerView?
Expand Down Expand Up @@ -268,6 +271,26 @@ class ContainableComposeViewController: ComposeContentViewController, BannerRequ
}

override func startSendingMessage() {
guard dependencies.internetConnectionStatusProvider.status.isConnected else {
collectDraftDataAndSaveToDB()
.done { [weak self] _ in
let alert = UIAlertController(
title: L10n.Compose.sendingWithShareExtensionWhileOfflineIsNotSupported,
message: L10n.Compose.messageSavedAsDraft,
preferredStyle: .alert
)
alert.addAction(.okAction() { [weak self] _ in
self?.dismissAnimation()
})
self?.stepAlert = alert
}
.catch { error in
PMAssertionFailure(error)
}

return
}

stepUpdateQueue.sync {
self.step = .sendingStarted
let alert = UIAlertController(
Expand All @@ -290,18 +313,15 @@ class ContainableComposeViewController: ComposeContentViewController, BannerRequ
}

private func dismissAnimation() {
DispatchQueue.main.async {
let animationBlock: () -> Void = { [weak self] in
if let view = self?.navigationController?.view {
view.transform = CGAffineTransform(translationX: 0, y: view.frame.size.height)
}
}
self.stepAlert = nil
self.dependencies.keyMaker.lockTheApp()
UIView.animate(withDuration: 0.25, animations: animationBlock) { _ in
SystemLogger.log(message: "Share extension is dismissing...", category: .appLifeCycle)
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
}
dependencies.keyMaker.lockTheApp()

SystemLogger.log(message: "Share extension is dismissing...", category: .appLifeCycle)

dependencies.queueManager.unregisterHandler(for: viewModel.user.userID) {
self.viewModel.user.container.reset()
self.viewModel.user.container.globalContainer.reset()

self.extensionContext?.completeRequest(returningItems: nil)
}
}

Expand Down

0 comments on commit 71e78f7

Please sign in to comment.