feat: decline and block screen

fix

improvement

fix conflict

fix tests

tests
This commit is contained in:
Mauro Romito
2025-04-03 17:36:34 +02:00
committed by Mauro
parent 2ee5c1b403
commit d92fecdc7e
32 changed files with 597 additions and 13 deletions
@@ -419,6 +419,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
return .reportRoom(previousState: fromState)
case (.reportRoom(let previousState), .dismissReportRoomScreen):
return previousState
case (.joinRoomScreen, .presentDeclineAndBlockScreen):
return .declineAndBlockScreen
case (.declineAndBlockScreen, .dismissDeclineAndBlockScreen):
return .joinRoomScreen
default:
return nil
@@ -595,6 +600,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
presentReportRoom()
case (.reportRoom, .dismissReportRoomScreen, .roomDetails):
break
case (.joinRoomScreen, .presentDeclineAndBlockScreen(let userID), .declineAndBlockScreen):
presentDeclineAndBlockScreen(userID: userID)
case (.declineAndBlockScreen, .dismissDeclineAndBlockScreen, .joinRoomScreen):
break
// Child flow
case (_, .startChildFlow(let roomID, let via, let entryPoint), .presentingChild):
@@ -799,6 +809,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
}
case .cancelled:
stateMachine.tryEvent(.dismissJoinRoomScreen)
case .presentDeclineAndBlock(let userID):
stateMachine.tryEvent(.presentDeclineAndBlockScreen(userID: userID))
}
}
.store(in: &cancellables)
@@ -1551,6 +1563,30 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
}
}
private func presentDeclineAndBlockScreen(userID: String) {
let stackCoordinator = NavigationStackCoordinator()
let coordinator = DeclineAndBlockScreenCoordinator(parameters: .init(userID: userID,
roomID: roomID,
clientProxy: userSession.clientProxy,
userIndicatorController: userIndicatorController))
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .dismiss(let hasDeclined):
if hasDeclined {
stateMachine.tryEvent(.dismissFlow)
}
navigationStackCoordinator.setSheetCoordinator(nil)
}
}
.store(in: &cancellables)
stackCoordinator.setRootCoordinator(coordinator)
navigationStackCoordinator.setSheetCoordinator(stackCoordinator) { [weak self] in
self?.stateMachine.tryEvent(.dismissDeclineAndBlockScreen)
}
}
// MARK: - Other flows
private func startChildFlow(for roomID: String, via: [String], entryPoint: RoomFlowCoordinatorEntryPoint) async {
@@ -1722,6 +1758,7 @@ private extension RoomFlowCoordinator {
case mediaEventsTimeline(previousState: State)
case securityAndPrivacy(previousState: State)
case reportRoom(previousState: State)
case declineAndBlockScreen
/// A child flow is in progress.
case presentingChild(childRoomID: String, previousState: State)
@@ -1811,5 +1848,8 @@ private extension RoomFlowCoordinator {
case presentReportRoomScreen
case dismissReportRoomScreen
case presentDeclineAndBlockScreen(userID: String)
case dismissDeclineAndBlockScreen
}
}
@@ -312,6 +312,11 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
case (.reportRoomScreen, .dismissedReportRoomScreen, .roomList):
break
case (.roomList, .presentDeclineAndBlockScreen(let userID, let roomID), .declineAndBlockUserScreen):
presentDeclineAndBlockScreen(userID: userID, roomID: roomID)
case (.declineAndBlockUserScreen, .dismissedDeclineAndBlockScreen, .roomList):
break
case (.roomList(let roomListSelectedRoomID), .showShareExtensionRoomList, .shareExtensionRoomList(let sharePayload)):
Task {
if roomListSelectedRoomID != nil {
@@ -526,6 +531,8 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
self.actionsSubject.send(.logout)
case .logout:
Task { await self.runLogoutFlow() }
case .presentDeclineAndBlock(let userID, let roomID):
stateMachine.processEvent(.presentDeclineAndBlockScreen(userID: userID, roomID: roomID))
}
}
.store(in: &cancellables)
@@ -564,6 +571,28 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
}
}
private func presentDeclineAndBlockScreen(userID: String, roomID: String) {
let stackCoordinator = NavigationStackCoordinator()
let coordinator = DeclineAndBlockScreenCoordinator(parameters: .init(userID: userID,
roomID: roomID,
clientProxy: userSession.clientProxy,
userIndicatorController: ServiceLocator.shared.userIndicatorController))
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .dismiss:
navigationSplitCoordinator.setSheetCoordinator(nil)
}
}
.store(in: &cancellables)
stackCoordinator.setRootCoordinator(coordinator)
navigationSplitCoordinator.setSheetCoordinator(stackCoordinator) { [weak self] in
self?.stateMachine.processEvent(.dismissedDeclineAndBlockScreen)
}
}
private func runLogoutFlow() async {
let secureBackupController = userSession.clientProxy.secureBackupController
@@ -47,6 +47,8 @@ class UserSessionFlowCoordinatorStateMachine {
case shareExtensionRoomList(sharePayload: ShareExtensionPayload)
case declineAndBlockUserScreen(roomListSelectedRoomID: String?)
/// The selected room ID from the state if available.
var roomListSelectedRoomID: String? {
switch self {
@@ -60,7 +62,8 @@ class UserSessionFlowCoordinatorStateMachine {
.startChatScreen(let roomListSelectedRoomID),
.logoutConfirmationScreen(let roomListSelectedRoomID),
.roomDirectorySearchScreen(let roomListSelectedRoomID),
.reportRoomScreen(let roomListSelectedRoomID):
.reportRoomScreen(let roomListSelectedRoomID),
.declineAndBlockUserScreen(let roomListSelectedRoomID):
roomListSelectedRoomID
}
}
@@ -128,6 +131,9 @@ class UserSessionFlowCoordinatorStateMachine {
case presentReportRoomScreen(roomID: String)
case dismissedReportRoomScreen
case presentDeclineAndBlockScreen(userID: String, roomID: String)
case dismissedDeclineAndBlockScreen
}
private let stateMachine: StateMachine<State, Event>
@@ -206,6 +212,11 @@ class UserSessionFlowCoordinatorStateMachine {
case (.reportRoomScreen(let roomListSelectedRoomID), .dismissedReportRoomScreen):
return .roomList(roomListSelectedRoomID: roomListSelectedRoomID)
case(.roomList(let roomListSelectedRoomID), .presentDeclineAndBlockScreen):
return .declineAndBlockUserScreen(roomListSelectedRoomID: roomListSelectedRoomID)
case (.declineAndBlockUserScreen(let roomListSelectedRoomID), .dismissedDeclineAndBlockScreen):
return .roomList(roomListSelectedRoomID: roomListSelectedRoomID)
default:
return nil
}