Rename completion to callback and simplify actor usage. (#6141)

This commit is contained in:
Doug
2022-05-11 13:18:26 +01:00
committed by GitHub
parent e0f459014c
commit 0417263fdb
12 changed files with 113 additions and 95 deletions
@@ -28,7 +28,7 @@ class AuthenticationServerSelectionViewModel: AuthenticationServerSelectionViewM
// MARK: Public
var completion: ((AuthenticationServerSelectionViewModelResult) -> Void)?
@MainActor var callback: ((AuthenticationServerSelectionViewModelResult) -> Void)?
// MARK: - Setup
@@ -41,20 +41,15 @@ class AuthenticationServerSelectionViewModel: AuthenticationServerSelectionViewM
// MARK: - Public
override func process(viewAction: AuthenticationServerSelectionViewAction) {
Task {
await MainActor.run {
switch viewAction {
case .confirm:
completion?(.confirm(homeserverAddress: state.bindings.homeserverAddress))
case .dismiss:
completion?(.dismiss)
case .getInTouch:
getInTouch()
case .clearFooterError:
guard state.footerErrorMessage != nil else { return }
withAnimation { state.footerErrorMessage = nil }
}
}
switch viewAction {
case .confirm:
Task { await callback?(.confirm(homeserverAddress: state.bindings.homeserverAddress)) }
case .dismiss:
Task { await callback?(.dismiss) }
case .getInTouch:
Task { await getInTouch() }
case .clearFooterError:
Task { await clearFooterError() }
}
}
@@ -71,6 +66,12 @@ class AuthenticationServerSelectionViewModel: AuthenticationServerSelectionViewM
// MARK: - Private
/// Clear any errors shown in the text field footer.
@MainActor private func clearFooterError() {
guard state.footerErrorMessage != nil else { return }
withAnimation { state.footerErrorMessage = nil }
}
/// Opens the EMS link in the user's browser.
@MainActor private func getInTouch() {
let url = BuildSettings.onboardingHostYourOwnServerLink