Files
bundesmessenger-ios/RiotSwiftUI/Modules/Authentication/ServerSelection/AuthenticationServerSelectionViewModel.swift
Frank Rotermund 67df1a3e95 chore: FOSS Merge 1.27.11 (MESSENGER-7276)
Merge commit 'af0b6d4be985d9f26e5111d3fa01389c7321949f' into feature/7276_FOSS_Merge_1_27_11

# Conflicts:
#	Config/AppVersion.xcconfig
#	Gemfile.lock
#	IDETemplateMacros.plist
#	Podfile
#	Podfile.lock
#	README.md
#	Riot/Modules/Authentication/AuthenticationCoordinator.swift
#	Riot/Modules/Room/CellData/RoomBubbleCellData.m
#	Riot/target.yml
#	RiotNSE/NotificationService.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/AuthenticationServerSelectionModels.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/AuthenticationServerSelectionViewModel.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/Coordinator/AuthenticationServerSelectionCoordinator.swift
#	RiotSwiftUI/Modules/Authentication/ServerSelection/View/AuthenticationServerSelectionScreen.swift
#	RiotSwiftUI/Modules/Room/CompletionSuggestion/Service/CompletionSuggestionService.swift
#	fastlane/Fastfile
2025-05-16 14:06:20 +02:00

81 lines
3.0 KiB
Swift

//
// Copyright 2021-2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import SwiftUI
typealias AuthenticationServerSelectionViewModelType = StateStoreViewModel<AuthenticationServerSelectionViewState, AuthenticationServerSelectionViewAction>
class AuthenticationServerSelectionViewModel: AuthenticationServerSelectionViewModelType, AuthenticationServerSelectionViewModelProtocol {
// MARK: - Properties
// MARK: Private
// MARK: Public
var callback: (@MainActor (AuthenticationServerSelectionViewModelResult) -> Void)?
// MARK: - Setup
init(homeserverAddress: String, flow: AuthenticationFlow, hasModalPresentation: Bool) {
var bindings = AuthenticationServerSelectionBindings(homeserverAddress: homeserverAddress)
if BWIBuildSettings.shared.bumLoginFlowLayout {
bindings.homeserverAddress = ""
}
super.init(initialViewState: AuthenticationServerSelectionViewState(bindings: bindings,
flow: flow,
hasModalPresentation: hasModalPresentation))
}
// MARK: - Public
override func process(viewAction: AuthenticationServerSelectionViewAction) {
switch viewAction {
case .confirm:
Task { await callback?(.confirm(homeserverAddress: state.bindings.homeserverAddress)) }
case .dismiss:
Task { await callback?(.dismiss) }
case .clearFooterError:
Task { await clearFooterError() }
case .downloadReplacementApp(let replacementApp):
Task { await callback?(.downloadReplacementApp(replacementApp)) }
}
}
@MainActor func displayError(_ type: AuthenticationServerSelectionErrorType) {
switch type {
case .footerMessage(let message):
withAnimation {
state.footerError = .message(message)
}
case .openURLAlert:
state.bindings.alertInfo = AlertInfo(id: .openURLAlert, title: VectorL10n.roomMessageUnableOpenLinkErrorMessage)
case .openInvalidServerInfo: break
case .requiresReplacementApp:
withAnimation {
state.footerError = .sunsetBanner
}
}
}
@MainActor func displayInfo(_ message: String, buttonTitle: String, completion: (()->Void)? ) {
state.bindings.alertInfo = AlertInfo(id: .openInvalidServerInfo,
title: message,
primaryButton: (buttonTitle, completion),
secondaryButton: (VectorL10n.cancel, nil))
}
// MARK: - Private
/// Clear any errors shown in the text field footer.
@MainActor private func clearFooterError() {
guard state.footerError != nil else { return }
withAnimation { state.footerError = nil }
}
}