mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Silence some warnings. (#4969)
This commit is contained in:
@@ -307,7 +307,7 @@ struct CreateRoom_Previews: PreviewProvider, TestablePreview {
|
||||
analytics: ServiceLocator.shared.analytics,
|
||||
userIndicatorController: UserIndicatorControllerMock(),
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
viewModel.updateAvatar(fileURL: Bundle.main.url(forResource: "preview_avatar_room", withExtension: "jpg")!)
|
||||
viewModel.updateAvatar(fileURL: Bundle.main.url(forResource: "preview_avatar_room", withExtension: "jpg") ?? .picturesDirectory)
|
||||
return viewModel
|
||||
}()
|
||||
|
||||
@@ -331,7 +331,7 @@ struct CreateRoom_Previews: PreviewProvider, TestablePreview {
|
||||
analytics: ServiceLocator.shared.analytics,
|
||||
userIndicatorController: UserIndicatorControllerMock(),
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
viewModel.updateAvatar(fileURL: Bundle.main.url(forResource: "preview_avatar_room", withExtension: "jpg")!)
|
||||
viewModel.updateAvatar(fileURL: Bundle.main.url(forResource: "preview_avatar_room", withExtension: "jpg") ?? .picturesDirectory)
|
||||
return viewModel
|
||||
}()
|
||||
|
||||
|
||||
@@ -37,33 +37,36 @@ enum QRCodeLoginScreenMode {
|
||||
|
||||
struct QRCodeLoginScreenViewState: BindableState {
|
||||
var state: QRCodeLoginState
|
||||
let mode: QRCodeLoginScreenMode
|
||||
/// Whether or not it is possible for the screen to start the manual sign in flow. This was added to avoid
|
||||
/// having to handle server configuration when ``AppSettings.allowOtherAccountProviders`` is false.
|
||||
let canSignInManually: Bool
|
||||
let isPresentedModally: Bool
|
||||
|
||||
let instructions = QRCodeLoginScreenInstructions()
|
||||
var bindings = QRCodeLoginScreenViewStateBindings()
|
||||
|
||||
var shouldDisplayCancelButton: Bool {
|
||||
// TODO: Simplify/validate these assumptions.
|
||||
if isPresentedModally {
|
||||
switch mode {
|
||||
case .login:
|
||||
switch state {
|
||||
case .loginInstructions, .scan, .error(.noCameraPermission): true
|
||||
default: false
|
||||
case .error: false
|
||||
case .linkDesktopInstructions, .displayCode, .displayQR, .confirmCode: false // Unreachable states.
|
||||
}
|
||||
} else {
|
||||
case .linkDesktop, .linkMobile:
|
||||
switch state {
|
||||
case .displayCode, .confirmCode, .scan, .error(.noCameraPermission): true
|
||||
case .loginInstructions, .linkDesktopInstructions, .displayQR, .error: false
|
||||
case .linkDesktopInstructions, .displayQR, .error: false
|
||||
case .loginInstructions: false // Unreachable state.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var shouldDisplayBackButton: Bool {
|
||||
if isPresentedModally {
|
||||
false
|
||||
} else {
|
||||
switch mode {
|
||||
case .login:
|
||||
false // Login is presented modally, never show the back button.
|
||||
case .linkDesktop, .linkMobile:
|
||||
switch state {
|
||||
case .loginInstructions, .linkDesktopInstructions, .displayQR: true
|
||||
case .displayCode, .confirmCode, .scan, .error: false
|
||||
|
||||
@@ -12,7 +12,6 @@ import Foundation
|
||||
typealias QRCodeLoginScreenViewModelType = StateStoreViewModel<QRCodeLoginScreenViewState, QRCodeLoginScreenViewAction>
|
||||
|
||||
class QRCodeLoginScreenViewModel: QRCodeLoginScreenViewModelType, QRCodeLoginScreenViewModelProtocol {
|
||||
private let mode: QRCodeLoginScreenMode
|
||||
private let appMediator: AppMediatorProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<QRCodeLoginScreenViewModelAction, Never> = .init()
|
||||
@@ -26,24 +25,19 @@ class QRCodeLoginScreenViewModel: QRCodeLoginScreenViewModelType, QRCodeLoginScr
|
||||
init(mode: QRCodeLoginScreenMode,
|
||||
canSignInManually: Bool,
|
||||
appMediator: AppMediatorProtocol) {
|
||||
self.mode = mode
|
||||
self.appMediator = appMediator
|
||||
|
||||
let initialState: QRCodeLoginScreenViewState = switch mode {
|
||||
case .login:
|
||||
.init(state: .loginInstructions, canSignInManually: canSignInManually, isPresentedModally: true)
|
||||
case .linkDesktop:
|
||||
.init(state: .linkDesktopInstructions, canSignInManually: canSignInManually, isPresentedModally: false)
|
||||
let initialViewState: QRCodeLoginState = switch mode {
|
||||
case .login: .loginInstructions
|
||||
case .linkDesktop: .linkDesktopInstructions
|
||||
case .linkMobile(let progressPublisher):
|
||||
switch progressPublisher.value {
|
||||
case .qrReady(let image):
|
||||
.init(state: .displayQR(image), canSignInManually: canSignInManually, isPresentedModally: false)
|
||||
default:
|
||||
.init(state: .error(.unknown), canSignInManually: canSignInManually, isPresentedModally: false)
|
||||
case .qrReady(let image): .displayQR(image)
|
||||
default: .error(.unknown)
|
||||
}
|
||||
}
|
||||
|
||||
super.init(initialViewState: initialState)
|
||||
super.init(initialViewState: .init(state: initialViewState, mode: mode, canSignInManually: canSignInManually))
|
||||
setupSubscriptions()
|
||||
|
||||
if case .linkMobile(let progressPublisher) = mode {
|
||||
@@ -62,7 +56,7 @@ class QRCodeLoginScreenViewModel: QRCodeLoginScreenViewModelType, QRCodeLoginScr
|
||||
case .sendCheckCode:
|
||||
Task { await sendCheckCode() }
|
||||
case .errorAction(.startOver):
|
||||
switch mode {
|
||||
switch state.mode {
|
||||
case .login:
|
||||
Task { await startScanIfPossible() }
|
||||
case .linkDesktop, .linkMobile:
|
||||
@@ -88,7 +82,7 @@ class QRCodeLoginScreenViewModel: QRCodeLoginScreenViewModelType, QRCodeLoginScr
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] qrData in
|
||||
guard let self else { return }
|
||||
switch mode {
|
||||
switch state.mode {
|
||||
case .login(let qrCodeLoginService):
|
||||
handleScan(qrData: qrData, loginService: qrCodeLoginService)
|
||||
case .linkDesktop(let linkNewDeviceService):
|
||||
@@ -152,8 +146,6 @@ class QRCodeLoginScreenViewModel: QRCodeLoginScreenViewModelType, QRCodeLoginScr
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: when user cancels in UI then the underlying login needs to be cancelled too. It's unclear if we have that exposed in the bindings yet.
|
||||
|
||||
private func handleScan(qrData: Data, linkService: LinkNewDeviceServiceProtocol) {
|
||||
guard currentTask == nil else { return }
|
||||
|
||||
@@ -314,24 +306,23 @@ class QRCodeLoginScreenViewModel: QRCodeLoginScreenViewModelType, QRCodeLoginScr
|
||||
}
|
||||
|
||||
/// Only for mocking initial states
|
||||
fileprivate init(state: QRCodeLoginState, canSignInManually: Bool, isPresentedModally: Bool, checkCodeInput: String) {
|
||||
mode = .login(QRCodeLoginServiceMock())
|
||||
fileprivate init(state: QRCodeLoginState, mode: QRCodeLoginScreenMode, canSignInManually: Bool, checkCodeInput: String) {
|
||||
appMediator = AppMediatorMock.default
|
||||
super.init(initialViewState: .init(state: state,
|
||||
mode: mode,
|
||||
canSignInManually: canSignInManually,
|
||||
isPresentedModally: isPresentedModally,
|
||||
bindings: .init(checkCodeInput: checkCodeInput)))
|
||||
}
|
||||
}
|
||||
|
||||
extension QRCodeLoginScreenViewModel {
|
||||
static func mock(state: QRCodeLoginState,
|
||||
mode: QRCodeLoginScreenMode = .login(QRCodeLoginServiceMock()),
|
||||
canSignInManually: Bool = true,
|
||||
isPresentedModally: Bool = true,
|
||||
checkCodeInput: String = "") -> QRCodeLoginScreenViewModel {
|
||||
QRCodeLoginScreenViewModel(state: state,
|
||||
mode: mode,
|
||||
canSignInManually: canSignInManually,
|
||||
isPresentedModally: isPresentedModally,
|
||||
checkCodeInput: checkCodeInput)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user