33 lines
1.1 KiB
Swift
33 lines
1.1 KiB
Swift
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()
|
|
}
|
|
}
|
|
}
|