another.im-ios/old/AppCore/Middlewares/StartMiddleware.swift

33 lines
1.1 KiB
Swift
Raw Normal View History

2024-06-19 15:15:27 +00:00
import Combine
final class StartMiddleware {
static let shared = StartMiddleware()
func middleware(state: AppState, action: AppAction) -> AnyPublisher<AppAction, Never> {
switch action {
case .accountsAction(.accountsListUpdated(let accounts)):
if accounts.isEmpty {
if state.currentFlow == .start {
return Just(.startAction(.goTo(.welcomeScreen)))
.eraseToAnyPublisher()
} else {
return Empty().eraseToAnyPublisher()
}
} else {
if state.currentFlow == .accounts, state.accountsState.navigation == .addAccount {
return Just(.changeFlow(.chats))
.eraseToAnyPublisher()
} else if state.currentFlow == .start {
return Just(.changeFlow(.chats))
.eraseToAnyPublisher()
} else {
return Empty().eraseToAnyPublisher()
}
}
default:
return Empty().eraseToAnyPublisher()
}
}
}