From 71e78f73c6adcff4c632c9f184a7b66ab8320a1b Mon Sep 17 00:00:00 2001 From: Jacek Krasiukianis Date: Wed, 31 Jul 2024 08:56:13 +0200 Subject: [PATCH] INBIOS-76 Fix sending from the Share extension while offline --- .../APP_share_push_uiTest/Localization.swift | 2 + .../ContainableComposeViewController.swift | 46 +++++++++++++------ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/ProtonMail/ProtonMail/Utilities/APP_share_push_uiTest/Localization.swift b/ProtonMail/ProtonMail/Utilities/APP_share_push_uiTest/Localization.swift index 3d0eb5ca9..3031c14ea 100644 --- a/ProtonMail/ProtonMail/Utilities/APP_share_push_uiTest/Localization.swift +++ b/ProtonMail/ProtonMail/Utilities/APP_share_push_uiTest/Localization.swift @@ -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 { diff --git a/ProtonMail/ProtonMail/ViewControllers/APP_share/Compose/EmbeddableCompose/ContainableComposeViewController.swift b/ProtonMail/ProtonMail/ViewControllers/APP_share/Compose/EmbeddableCompose/ContainableComposeViewController.swift index c53bfaef0..d7eb94ff0 100644 --- a/ProtonMail/ProtonMail/ViewControllers/APP_share/Compose/EmbeddableCompose/ContainableComposeViewController.swift +++ b/ProtonMail/ProtonMail/ViewControllers/APP_share/Compose/EmbeddableCompose/ContainableComposeViewController.swift @@ -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? @@ -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( @@ -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) } }