Skip to content

Commit

Permalink
Move proxy-handling-alert-showing-code to app-coordinator (#2389)
Browse files Browse the repository at this point in the history
Thanks @r10s, I'm convinced
  • Loading branch information
zeitschlag committed Nov 15, 2024
1 parent 8bafa0e commit 774a55b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 54 deletions.
30 changes: 4 additions & 26 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2381,8 +2381,10 @@ extension ChatViewController: BaseMessageCellDelegate {
if Utils.isEmail(url: url) {
let email = Utils.getEmailFrom(url)
self.askToChatWith(email: email)
} else if Utils.isProxy(url: url, dcContext: dcContext) {
selectProxy(url: url.absoluteString)
} else if Utils.isProxy(url: url, dcContext: dcContext),
let appDelegate = UIApplication.shared.delegate as? AppDelegate,
let appCoordinator = appDelegate.appCoordinator {
appCoordinator.handleProxySelection(on: self, dcContext: dcContext, proxyURL: url.absoluteString)
} else if url.isDeltaChatInvitation,
let appDelegate = UIApplication.shared.delegate as? AppDelegate,
let appCoordinator = appDelegate.appCoordinator {
Expand All @@ -2392,30 +2394,6 @@ extension ChatViewController: BaseMessageCellDelegate {
}
}

private func selectProxy(url proxyURL: String) {
let host = dcContext.checkQR(qrCode: proxyURL).text1 ?? ""
let dcAccounts = DcAccounts.shared

let selectAlert = UIAlertController(
title: String.localized("proxy_use_proxy"),
message: String.localized(stringID: "proxy_use_proxy_confirm", parameter: host),
preferredStyle: .alert
)

let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel)
let selectAction = UIAlertAction(title: String.localized("proxy_use_proxy"), style: .default) { [weak self] _ in

guard let self else { return }
if self.dcContext.setConfigFromQR(qrCode: proxyURL) {
dcAccounts.restartIO()
}
}

selectAlert.addAction(cancelAction)
selectAlert.addAction(selectAction)

present(selectAlert, animated: true)
}

@objc func imageTapped(indexPath: IndexPath, previewError: Bool) {
if handleUIMenu() || handleSelection(indexPath: indexPath) {
Expand Down
32 changes: 4 additions & 28 deletions deltachat-ios/Controller/ContactDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,10 @@ extension ContactDetailViewController: MultilineLabelCellDelegate {
}))
alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
} else if Utils.isProxy(url: url, dcContext: viewModel.context) {
selectProxy(url: url.absoluteString)
} else if Utils.isProxy(url: url, dcContext: viewModel.context),
let appDelegate = UIApplication.shared.delegate as? AppDelegate,
let appCoordinator = appDelegate.appCoordinator {
appCoordinator.handleProxySelection(on: self, dcContext: viewModel.context, proxyURL: url.absoluteString)
} else if url.isDeltaChatInvitation,
let appDelegate = UIApplication.shared.delegate as? AppDelegate,
let appCoordinator = appDelegate.appCoordinator {
Expand All @@ -610,30 +612,4 @@ extension ContactDetailViewController: MultilineLabelCellDelegate {
UIApplication.shared.open(url)
}
}

private func selectProxy(url proxyURL: String) {
let host = viewModel.context.checkQR(qrCode: proxyURL).text1 ?? ""
let dcAccounts = DcAccounts.shared

let selectAlert = UIAlertController(
title: String.localized("proxy_use_proxy"),
message: String.localized(stringID: "proxy_use_proxy_confirm", parameter: host),
preferredStyle: .alert
)

let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel)
let selectAction = UIAlertAction(title: String.localized("proxy_use_proxy"), style: .default) { [weak self] _ in

guard let self else { return }
if self.viewModel.context.setConfigFromQR(qrCode: proxyURL) {
dcAccounts.restartIO()
}
}

selectAlert.addAction(cancelAction)
selectAlert.addAction(selectAction)

present(selectAlert, animated: true)
}

}
24 changes: 24 additions & 0 deletions deltachat-ios/Coordinator/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,30 @@ class AppCoordinator: NSObject {
coordinate(qrCode: url.absoluteString, from: viewController)
}

func handleProxySelection(on viewController: UIViewController, dcContext: DcContext, proxyURL: String) {
let host = dcContext.checkQR(qrCode: proxyURL).text1 ?? ""

let selectAlert = UIAlertController(
title: String.localized("proxy_use_proxy"),
message: String.localized(stringID: "proxy_use_proxy_confirm", parameter: host),
preferredStyle: .alert
)

let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel)
let selectAction = UIAlertAction(title: String.localized("proxy_use_proxy"), style: .default) { [weak self] _ in

guard let self else { return }
if dcContext.setConfigFromQR(qrCode: proxyURL) {
dcAccounts.restartIO()
}
}

selectAlert.addAction(cancelAction)
selectAlert.addAction(selectAction)

viewController.present(selectAlert, animated: true)
}

func handleQRCode(_ code: String) {
if code.lowercased().starts(with: "dcaccount:")
|| code.lowercased().starts(with: "dclogin:") {
Expand Down

0 comments on commit 774a55b

Please sign in to comment.