mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-24 18:42:47 +02:00
Rename completion to callback and simplify actor usage. (#6141)
This commit is contained in:
+19
-18
@@ -48,7 +48,7 @@ final class AuthenticationServerSelectionCoordinator: Coordinator, Presentable {
|
||||
|
||||
// Must be used only internally
|
||||
var childCoordinators: [Coordinator] = []
|
||||
@MainActor var completion: ((AuthenticationServerSelectionCoordinatorResult) -> Void)?
|
||||
@MainActor var callback: ((AuthenticationServerSelectionCoordinatorResult) -> Void)?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
@@ -70,22 +70,8 @@ final class AuthenticationServerSelectionCoordinator: Coordinator, Presentable {
|
||||
// MARK: - Public
|
||||
|
||||
func start() {
|
||||
Task {
|
||||
await MainActor.run {
|
||||
MXLog.debug("[AuthenticationServerSelectionCoordinator] did start.")
|
||||
authenticationServerSelectionViewModel.completion = { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
MXLog.debug("[AuthenticationServerSelectionCoordinator] AuthenticationServerSelectionViewModel did complete with result: \(result).")
|
||||
|
||||
switch result {
|
||||
case .confirm(let homeserverAddress):
|
||||
self.useHomeserver(homeserverAddress)
|
||||
case .dismiss:
|
||||
self.completion?(.dismiss)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
MXLog.debug("[AuthenticationServerSelectionCoordinator] did start.")
|
||||
Task { await setupViewModel() }
|
||||
}
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
@@ -94,6 +80,21 @@ final class AuthenticationServerSelectionCoordinator: Coordinator, Presentable {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
/// Set up the view model. This method is extracted from `start()` so it can run on the `MainActor`.
|
||||
@MainActor private func setupViewModel() {
|
||||
authenticationServerSelectionViewModel.callback = { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
MXLog.debug("[AuthenticationServerSelectionCoordinator] AuthenticationServerSelectionViewModel did complete with result: \(result).")
|
||||
|
||||
switch result {
|
||||
case .confirm(let homeserverAddress):
|
||||
self.useHomeserver(homeserverAddress)
|
||||
case .dismiss:
|
||||
self.callback?(.dismiss)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Show an activity indicator whilst loading.
|
||||
/// - Parameters:
|
||||
/// - label: The label to show on the indicator.
|
||||
@@ -120,7 +121,7 @@ final class AuthenticationServerSelectionCoordinator: Coordinator, Presentable {
|
||||
try await authenticationService.startFlow(.register, for: homeserverAddress)
|
||||
stopLoading()
|
||||
|
||||
completion?(.updated)
|
||||
callback?(.updated)
|
||||
} catch {
|
||||
stopLoading()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user