mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 00:49:44 +00:00
implemented the flow to create room in a selected space
This commit is contained in:
@@ -44,6 +44,7 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
|
||||
private var membersFlowCoordinator: RoomMembersFlowCoordinator?
|
||||
private var settingsFlowCoordinator: SpaceSettingsFlowCoordinator?
|
||||
private var rolesAndPermissionsFlowCoordinator: RoomRolesAndPermissionsFlowCoordinator?
|
||||
private var createChildRoomFlowCoordinator: StartChatFlowCoordinator?
|
||||
|
||||
indirect enum State: StateType {
|
||||
/// The state machine hasn't started.
|
||||
@@ -65,6 +66,8 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
|
||||
|
||||
case rolesAndPermissionsFlow
|
||||
|
||||
case createChildRoomFlow
|
||||
|
||||
case leftSpace
|
||||
}
|
||||
|
||||
@@ -102,6 +105,9 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
|
||||
|
||||
case startRolesAndPermissionsFlow
|
||||
case stopRolesAndPermissionsFlow
|
||||
|
||||
case startCreateChildRoomFlow
|
||||
case stopCreateChildRoomFlow
|
||||
}
|
||||
|
||||
private let stateMachine: StateMachine<State, Event>
|
||||
@@ -170,12 +176,15 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
|
||||
case .rolesAndPermissionsFlow:
|
||||
rolesAndPermissionsFlowCoordinator?.clearRoute(animated: animated)
|
||||
clearRoute(animated: animated) // Re-run with the state machine back in the .space state.
|
||||
case .createChildRoomFlow:
|
||||
createChildRoomFlowCoordinator?.clearRoute(animated: animated)
|
||||
clearRoute(animated: animated) // Re-run with the state machine back in the .space state.
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
// swiftlint:disable:next function_body_length cyclomatic_complexity
|
||||
private func configureStateMachine() {
|
||||
stateMachine.addRoutes(event: .start, transitions: [.initial => .space]) { [weak self] _ in
|
||||
self?.presentSpace()
|
||||
@@ -288,6 +297,21 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
|
||||
rolesAndPermissionsFlowCoordinator = nil
|
||||
}
|
||||
|
||||
stateMachine.addRouteMapping { event, fromState, _ in
|
||||
guard event == .startCreateChildRoomFlow, case .space = fromState else { return nil }
|
||||
return .createChildRoomFlow
|
||||
} handler: { [weak self] context in
|
||||
guard let space = context.userInfo as? SpaceServiceRoomProtocol else { fatalError("The space is missing") }
|
||||
self?.startCreateChildFlow(space: space)
|
||||
}
|
||||
|
||||
stateMachine.addRouteMapping { event, fromState, _ in
|
||||
guard event == .stopCreateChildRoomFlow, case .createChildRoomFlow = fromState else { return nil }
|
||||
return .space
|
||||
} handler: { [weak self] _ in
|
||||
self?.createChildRoomFlowCoordinator = nil
|
||||
}
|
||||
|
||||
stateMachine.addErrorHandler { context in
|
||||
fatalError("Unexpected transition: \(context)")
|
||||
}
|
||||
@@ -323,6 +347,8 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
|
||||
stateMachine.tryEvent(.startRolesAndPermissionsFlow, userInfo: roomProxy)
|
||||
case .addExistingChildren:
|
||||
stateMachine.tryEvent(.addRooms)
|
||||
case .displayCreateChildRoomFlow(let space):
|
||||
stateMachine.tryEvent(.startCreateChildRoomFlow, userInfo: space)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
@@ -534,4 +560,41 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
|
||||
rolesAndPermissionsFlowCoordinator = flowCoordinator
|
||||
flowCoordinator.start()
|
||||
}
|
||||
|
||||
private func startCreateChildFlow(space: SpaceServiceRoomProtocol) {
|
||||
let stackCoordinator = NavigationStackCoordinator()
|
||||
let flowCoordinator = StartChatFlowCoordinator(entryPoint: .createRoomInSpace(space),
|
||||
userDiscoveryService: UserDiscoveryService(clientProxy: flowParameters.userSession.clientProxy),
|
||||
navigationStackCoordinator: stackCoordinator,
|
||||
flowParameters: flowParameters)
|
||||
|
||||
var flowCoordinatorResult: StartChatFlowCoordinatorAction.Result?
|
||||
flowCoordinator.actionsPublisher.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .finished(let result):
|
||||
flowCoordinatorResult = result
|
||||
navigationStackCoordinator.setSheetCoordinator(nil)
|
||||
case .showRoomDirectory:
|
||||
fatalError("Not implemented yet")
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
navigationStackCoordinator.setSheetCoordinator(stackCoordinator) { [weak self] in
|
||||
guard let self else { return }
|
||||
stateMachine.tryEvent(.stopCreateChildRoomFlow)
|
||||
switch flowCoordinatorResult {
|
||||
case .room(let id):
|
||||
stateMachine.tryEvent(.startRoomFlow(roomID: id))
|
||||
case .space(let spaceRoomListProxy):
|
||||
stateMachine.tryEvent(.startChildFlow, userInfo: spaceRoomListProxy)
|
||||
case .cancelled, .none:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
createChildRoomFlowCoordinator = flowCoordinator
|
||||
flowCoordinator.start()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ class SpacesTabFlowCoordinator: FlowCoordinatorProtocol {
|
||||
.store(in: &cancellables)
|
||||
|
||||
navigationSplitCoordinator.setSheetCoordinator(coordinator) { [weak self] in
|
||||
self?.stateMachine.tryEvent(.dismissedCreateSpaceFlow, userInfo: spaceRoomListProxy)
|
||||
self?.stateMachine.tryEvent(.dismissedCreateSpaceFlow)
|
||||
}
|
||||
|
||||
flowCoordinator.start(animated: true)
|
||||
|
||||
@@ -25,6 +25,7 @@ enum StartChatFlowCoordinatorAction {
|
||||
enum StartChatFlowCoordinatorEntryPoint {
|
||||
case startChat
|
||||
case createSpace
|
||||
case createRoomInSpace(SpaceServiceRoomProtocol)
|
||||
}
|
||||
|
||||
class StartChatFlowCoordinator: FlowCoordinatorProtocol {
|
||||
@@ -57,7 +58,7 @@ class StartChatFlowCoordinator: FlowCoordinatorProtocol {
|
||||
|
||||
enum Event: EventType {
|
||||
/// The flow is being started.
|
||||
case start(entryPoint: StartChatFlowCoordinatorEntryPoint)
|
||||
case start
|
||||
|
||||
/// The user would like to create a room.
|
||||
case createRoom
|
||||
@@ -96,7 +97,7 @@ class StartChatFlowCoordinator: FlowCoordinatorProtocol {
|
||||
}
|
||||
|
||||
func start(animated: Bool) {
|
||||
stateMachine.tryEvent(.start(entryPoint: entryPoint))
|
||||
stateMachine.tryEvent(.start)
|
||||
}
|
||||
|
||||
func handleAppRoute(_ appRoute: AppRoute, animated: Bool) {
|
||||
@@ -126,12 +127,24 @@ class StartChatFlowCoordinator: FlowCoordinatorProtocol {
|
||||
// MARK: - Private
|
||||
|
||||
private func configureStateMachine() {
|
||||
stateMachine.addRoutes(event: .start(entryPoint: .startChat), transitions: [.initial => .startChat]) { [weak self] _ in
|
||||
self?.presentStartChatScreen()
|
||||
}
|
||||
|
||||
stateMachine.addRoutes(event: .start(entryPoint: .createSpace), transitions: [.initial => .createRoom]) { [weak self] _ in
|
||||
self?.presentCreateRoomScreen(isSpace: true, isRoot: true)
|
||||
stateMachine.addRouteMapping { [weak self] event, fromState, _ in
|
||||
guard let self, event == .start, fromState == .initial else { return nil }
|
||||
switch entryPoint {
|
||||
case .startChat:
|
||||
return .startChat
|
||||
case .createSpace, .createRoomInSpace:
|
||||
return .createRoom
|
||||
}
|
||||
} handler: { [weak self] _ in
|
||||
guard let self else { return }
|
||||
switch entryPoint {
|
||||
case .startChat:
|
||||
presentStartChatScreen()
|
||||
case .createSpace:
|
||||
presentCreateRoomScreen(isSpace: true, isRoot: true)
|
||||
case .createRoomInSpace(let space):
|
||||
presentCreateRoomScreen(isSpace: false, selectedSpace: space, isRoot: true)
|
||||
}
|
||||
}
|
||||
|
||||
stateMachine.addRoutes(event: .createRoom, transitions: [.startChat => .createRoom]) { [weak self] _ in
|
||||
@@ -191,9 +204,17 @@ class StartChatFlowCoordinator: FlowCoordinatorProtocol {
|
||||
navigationStackCoordinator.setRootCoordinator(coordinator)
|
||||
}
|
||||
|
||||
private func presentCreateRoomScreen(isSpace: Bool, isRoot: Bool) {
|
||||
private func presentCreateRoomScreen(isSpace: Bool, selectedSpace: SpaceServiceRoomProtocol? = nil, isRoot: Bool) {
|
||||
let spaceSelectionMode: CreateRoomScreenSpaceSelectionMode? = if let selectedSpace {
|
||||
.selected(selectedSpace)
|
||||
} else if !isSpace, flowParameters.appSettings.createSpaceEnabled {
|
||||
.list
|
||||
} else {
|
||||
nil
|
||||
}
|
||||
|
||||
let createParameters = CreateRoomScreenCoordinatorParameters(isSpace: isSpace,
|
||||
spaceSelectionMode: !isSpace && flowParameters.appSettings.createSpaceEnabled ? .list : nil,
|
||||
spaceSelectionMode: spaceSelectionMode,
|
||||
shouldShowCancelButton: isRoot,
|
||||
userSession: flowParameters.userSession,
|
||||
userIndicatorController: flowParameters.userIndicatorController,
|
||||
|
||||
Reference in New Issue
Block a user