Skip to content

Commit 9338916

Browse files
authored
Introduce a StartChatFlowCoordinator instead of handing a navigation stack to the Screen Coordinator. (#4674)
* Introduce a basic StartChatFlowCoordinator. * Move the rest of the start chat flow from the screen coordinator into the flow coordinator. * Add a UI test for the entire start chat flow. * Refactor CreateRoom… to CreateRoomScreen…
1 parent 401ff49 commit 9338916

File tree

68 files changed

+765
-790
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+765
-790
lines changed

ElementX.xcodeproj/project.pbxproj

Lines changed: 44 additions & 56 deletions
Large diffs are not rendered by default.

ElementX/Sources/FlowCoordinators/ChatsFlowCoordinator.swift

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ class ChatsFlowCoordinator: FlowCoordinatorProtocol {
3636

3737
// periphery:ignore - retaining purpose
3838
private var bugReportFlowCoordinator: BugReportFlowCoordinator?
39-
4039
// periphery:ignore - retaining purpose
4140
private var encryptionResetFlowCoordinator: EncryptionResetFlowCoordinator?
41+
// periphery:ignore - retaining purpose
42+
private var startChatFlowCoordinator: StartChatFlowCoordinator?
4243

4344
// periphery:ignore - retaining purpose
4445
private var globalSearchScreenCoordinator: GlobalSearchScreenCoordinator?
@@ -223,12 +224,12 @@ class ChatsFlowCoordinator: FlowCoordinatorProtocol {
223224
case (.roomList, .startEncryptionResetFlow, .encryptionResetFlow):
224225
startEncryptionResetFlow(animated: animated)
225226
case (.encryptionResetFlow, .finishedEncryptionResetFlow, .roomList):
226-
break
227+
encryptionResetFlowCoordinator = nil
227228

228-
case (.roomList, .showStartChatScreen, .startChatScreen):
229-
presentStartChat(animated: animated)
230-
case (.startChatScreen, .dismissedStartChatScreen, .roomList):
231-
break
229+
case (.roomList, .startStartChatFlow, .startChatFlow):
230+
startStartChatFlow(animated: animated)
231+
case (.startChatFlow, .finishedStartChatFlow, .roomList):
232+
startChatFlowCoordinator = nil
232233

233234
case (.roomList, .showRoomDirectorySearchScreen, .roomDirectorySearchScreen):
234235
presentRoomDirectorySearch()
@@ -398,7 +399,7 @@ class ChatsFlowCoordinator: FlowCoordinatorProtocol {
398399
case .presentEncryptionResetScreen:
399400
stateMachine.processEvent(.startEncryptionResetFlow)
400401
case .presentStartChatScreen:
401-
stateMachine.processEvent(.showStartChatScreen)
402+
stateMachine.processEvent(.startStartChatFlow)
402403
case .presentGlobalSearch:
403404
presentGlobalSearch()
404405
case .logout:
@@ -565,39 +566,34 @@ class ChatsFlowCoordinator: FlowCoordinatorProtocol {
565566

566567
// MARK: Start Chat
567568

568-
private func presentStartChat(animated: Bool) {
569-
let startChatNavigationStackCoordinator = NavigationStackCoordinator()
570-
571-
let userDiscoveryService = UserDiscoveryService(clientProxy: userSession.clientProxy)
572-
let parameters = StartChatScreenCoordinatorParameters(orientationManager: flowParameters.windowManager,
573-
userSession: userSession,
574-
userIndicatorController: flowParameters.userIndicatorController,
575-
navigationStackCoordinator: startChatNavigationStackCoordinator,
576-
userDiscoveryService: userDiscoveryService,
577-
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: flowParameters.appSettings),
578-
appSettings: flowParameters.appSettings,
579-
analytics: flowParameters.analytics)
580-
581-
let coordinator = StartChatScreenCoordinator(parameters: parameters)
582-
coordinator.actions.sink { [weak self] action in
583-
guard let self else { return }
584-
switch action {
585-
case .close:
586-
navigationSplitCoordinator.setSheetCoordinator(nil)
587-
case .openRoom(let roomID):
588-
navigationSplitCoordinator.setSheetCoordinator(nil)
589-
stateMachine.processEvent(.selectRoom(roomID: roomID, via: [], entryPoint: .room))
590-
case .openRoomDirectorySearch:
591-
navigationSplitCoordinator.setSheetCoordinator(nil)
592-
stateMachine.processEvent(.showRoomDirectorySearchScreen)
569+
private func startStartChatFlow(animated: Bool) {
570+
let navigationStackCoordinator = NavigationStackCoordinator()
571+
let coordinator = StartChatFlowCoordinator(userDiscoveryService: UserDiscoveryService(clientProxy: userSession.clientProxy),
572+
navigationStackCoordinator: navigationStackCoordinator,
573+
flowParameters: flowParameters)
574+
575+
coordinator.actionsPublisher
576+
.sink { [weak self] action in
577+
guard let self else { return }
578+
switch action {
579+
case .finished(let roomID):
580+
navigationSplitCoordinator.setSheetCoordinator(nil)
581+
582+
if let roomID {
583+
stateMachine.processEvent(.selectRoom(roomID: roomID, via: [], entryPoint: .room))
584+
}
585+
case .showRoomDirectory:
586+
navigationSplitCoordinator.setSheetCoordinator(nil)
587+
stateMachine.processEvent(.showRoomDirectorySearchScreen)
588+
}
593589
}
594-
}
595-
.store(in: &cancellables)
596-
597-
startChatNavigationStackCoordinator.setRootCoordinator(coordinator)
598-
599-
navigationSplitCoordinator.setSheetCoordinator(startChatNavigationStackCoordinator, animated: animated) { [weak self] in
600-
self?.stateMachine.processEvent(.dismissedStartChatScreen)
590+
.store(in: &cancellables)
591+
592+
startChatFlowCoordinator = coordinator
593+
coordinator.start()
594+
595+
navigationSplitCoordinator.setSheetCoordinator(navigationStackCoordinator, animated: animated) { [weak self] in
596+
self?.stateMachine.processEvent(.finishedStartChatFlow)
601597
}
602598
}
603599

@@ -639,10 +635,8 @@ class ChatsFlowCoordinator: FlowCoordinatorProtocol {
639635
guard let self else { return }
640636
switch action {
641637
case .resetComplete:
642-
encryptionResetFlowCoordinator = nil
643638
navigationSplitCoordinator.setSheetCoordinator(nil)
644639
case .cancel:
645-
encryptionResetFlowCoordinator = nil
646640
navigationSplitCoordinator.setSheetCoordinator(nil)
647641
}
648642
}

ElementX/Sources/FlowCoordinators/ChatsFlowCoordinatorStateMachine.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class ChatsFlowCoordinatorStateMachine {
3333
/// Showing the encryption reset flow.
3434
case encryptionResetFlow(detailState: DetailState?)
3535

36-
/// Showing the start chat screen
37-
case startChatScreen(detailState: DetailState?)
36+
/// Showing the start chat flow
37+
case startChatFlow(detailState: DetailState?)
3838

3939
/// Showing the logout flows
4040
case logoutConfirmationScreen(detailState: DetailState?)
@@ -61,7 +61,7 @@ class ChatsFlowCoordinatorStateMachine {
6161
.feedbackScreen(let detailState),
6262
.recoveryKeyScreen(let detailState),
6363
.encryptionResetFlow(let detailState),
64-
.startChatScreen(let detailState),
64+
.startChatFlow(let detailState),
6565
.logoutConfirmationScreen(let detailState),
6666
.roomDirectorySearchScreen(let detailState),
6767
.reportRoomScreen(let detailState),
@@ -111,10 +111,10 @@ class ChatsFlowCoordinatorStateMachine {
111111
/// The encryption reset flow is complete and has been dismissed.
112112
case finishedEncryptionResetFlow
113113

114-
/// Request the start of the start chat flow
115-
case showStartChatScreen
116-
/// Start chat has been dismissed
117-
case dismissedStartChatScreen
114+
/// Request the start of the start chat flow.
115+
case startStartChatFlow
116+
/// The Start Chat flow is complete and has been dismissed.
117+
case finishedStartChatFlow
118118

119119
/// Request presentation of the room directory search screen.
120120
case showRoomDirectorySearchScreen
@@ -177,9 +177,9 @@ class ChatsFlowCoordinatorStateMachine {
177177
case (.encryptionResetFlow(let detailState), .finishedEncryptionResetFlow):
178178
return .roomList(detailState: detailState)
179179

180-
case (.roomList(let detailState), .showStartChatScreen):
181-
return .startChatScreen(detailState: detailState)
182-
case (.startChatScreen(let detailState), .dismissedStartChatScreen):
180+
case (.roomList(let detailState), .startStartChatFlow):
181+
return .startChatFlow(detailState: detailState)
182+
case (.startChatFlow(let detailState), .finishedStartChatFlow):
183183
return .roomList(detailState: detailState)
184184

185185
case (.roomList(let detailState), .showRoomDirectorySearchScreen):

ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,12 +1267,10 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
12671267
}
12681268

12691269
private func presentInviteUsersScreen() {
1270-
let selectedUsersSubject: CurrentValueSubject<[UserProfileProxy], Never> = .init([])
1271-
12721270
let stackCoordinator = NavigationStackCoordinator()
12731271
let inviteParameters = InviteUsersScreenCoordinatorParameters(userSession: userSession,
1274-
selectedUsers: .init(selectedUsersSubject),
1275-
roomType: .room(roomProxy: roomProxy),
1272+
roomProxy: roomProxy,
1273+
isSkippable: false,
12761274
userDiscoveryService: UserDiscoveryService(clientProxy: userSession.clientProxy),
12771275
userIndicatorController: flowParameters.userIndicatorController,
12781276
appSettings: flowParameters.appSettings)
@@ -1286,8 +1284,6 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
12861284
switch action {
12871285
case .dismiss:
12881286
navigationStackCoordinator.setSheetCoordinator(nil)
1289-
case .proceed:
1290-
fatalError("Not handled in this flow.")
12911287
}
12921288
}
12931289
.store(in: &cancellables)

ElementX/Sources/FlowCoordinators/RoomMembersFlowCoordinator.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ final class RoomMembersFlowCoordinator: FlowCoordinatorProtocol {
255255
private func presentInviteUsersScreen() {
256256
let stackCoordinator = NavigationStackCoordinator()
257257
let inviteParameters = InviteUsersScreenCoordinatorParameters(userSession: flowParameters.userSession,
258-
selectedUsers: nil,
259-
roomType: .room(roomProxy: roomProxy),
258+
roomProxy: roomProxy,
259+
isSkippable: false,
260260
userDiscoveryService: UserDiscoveryService(clientProxy: flowParameters.userSession.clientProxy),
261261
userIndicatorController: flowParameters.userIndicatorController,
262262
appSettings: flowParameters.appSettings)
@@ -270,8 +270,6 @@ final class RoomMembersFlowCoordinator: FlowCoordinatorProtocol {
270270
switch action {
271271
case .dismiss:
272272
navigationStackCoordinator.setSheetCoordinator(nil)
273-
case .proceed:
274-
fatalError("Not handled in this flow.")
275273
}
276274
}
277275
.store(in: &cancellables)

0 commit comments

Comments
 (0)