mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Space flow improvements. (#4430)
* Space flow improvements - Use a state machine to select a space. - Add a SpaceFlowCoordinator for recursively presenting subspaces. - Get the spaceRoomListProxy when tapping on the space so we can indicate failures. - Fix the total room count in SpaceListScreen. * Refactor spaceRoom → spaceRoomProxy. * Add a UI test for the Spaces flow.
This commit is contained in:
@@ -22,21 +22,31 @@ class SpaceExplorerFlowCoordinator: FlowCoordinatorProtocol {
|
||||
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private var spaceFlowCoordinator: SpaceFlowCoordinator?
|
||||
|
||||
enum State: StateType {
|
||||
/// The state machine hasn't started.
|
||||
case initial
|
||||
/// The root screen for this flow.
|
||||
case spaceList
|
||||
case spaceList(selectedSpaceID: String?)
|
||||
}
|
||||
|
||||
enum Event: EventType {
|
||||
/// The flow is being started.
|
||||
case start
|
||||
/// Request presentation for a particular space.
|
||||
///
|
||||
/// The space's `SpaceRoomListProxyProtocol` must be provided in the `userInfo`.
|
||||
case selectSpace
|
||||
/// The space screen has been dismissed.
|
||||
case deselectSpace
|
||||
}
|
||||
|
||||
private let stateMachine: StateMachine<State, Event>
|
||||
private var cancellables: Set<AnyCancellable> = []
|
||||
|
||||
private let selectedSpaceSubject = CurrentValueSubject<String?, Never>(nil)
|
||||
|
||||
private let actionsSubject: PassthroughSubject<SpaceExplorerFlowCoordinatorAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<SpaceExplorerFlowCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
@@ -77,30 +87,79 @@ class SpaceExplorerFlowCoordinator: FlowCoordinatorProtocol {
|
||||
// MARK: - Private
|
||||
|
||||
private func configureStateMachine() {
|
||||
stateMachine.addRoutes(event: .start, transitions: [.initial => .spaceList]) { [weak self] _ in
|
||||
stateMachine.addRoutes(event: .start, transitions: [.initial => .spaceList(selectedSpaceID: nil)]) { [weak self] _ in
|
||||
self?.presentSpaceList()
|
||||
}
|
||||
|
||||
stateMachine.addRouteMapping { event, fromState, userInfo in
|
||||
guard event == .selectSpace, case .spaceList = fromState else { return nil }
|
||||
guard let spaceRoomListProxy = userInfo as? SpaceRoomListProxyProtocol else { fatalError("A space proxy must be provided.") }
|
||||
return .spaceList(selectedSpaceID: spaceRoomListProxy.spaceRoom.id)
|
||||
} handler: { [weak self] context in
|
||||
guard let self, let spaceRoomListProxy = context.userInfo as? SpaceRoomListProxyProtocol else { return }
|
||||
startSpaceFlow(spaceRoomListProxy: spaceRoomListProxy)
|
||||
}
|
||||
|
||||
stateMachine.addRouteMapping { event, fromState, _ in
|
||||
guard event == .deselectSpace, case .spaceList(.some) = fromState else { return nil }
|
||||
return .spaceList(selectedSpaceID: nil)
|
||||
} handler: { [weak self] _ in
|
||||
guard let self else { return }
|
||||
selectedSpaceSubject.send(nil)
|
||||
spaceFlowCoordinator = nil
|
||||
}
|
||||
|
||||
stateMachine.addErrorHandler { context in
|
||||
fatalError("Unexpected transition: \(context)")
|
||||
}
|
||||
}
|
||||
|
||||
private func presentSpaceList() {
|
||||
// Temporarily using the mock until the SDK is updated.
|
||||
let parameters = SpaceListScreenCoordinatorParameters(userSession: userSession, spaceServiceProxy: SpaceServiceProxyMock(.init()))
|
||||
let parameters = SpaceListScreenCoordinatorParameters(userSession: userSession,
|
||||
selectedSpaceSubject: selectedSpaceSubject.asCurrentValuePublisher(),
|
||||
userIndicatorController: userIndicatorController)
|
||||
let coordinator = SpaceListScreenCoordinator(parameters: parameters)
|
||||
coordinator.actionsPublisher.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .showSettings:
|
||||
actionsSubject.send(.showSettings)
|
||||
case .selectSpace:
|
||||
break
|
||||
coordinator.actionsPublisher
|
||||
.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .selectSpace(let spaceRoomListProxy):
|
||||
stateMachine.tryEvent(.selectSpace, userInfo: spaceRoomListProxy)
|
||||
case .showSettings:
|
||||
actionsSubject.send(.showSettings)
|
||||
}
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
.store(in: &cancellables)
|
||||
|
||||
sidebarNavigationStackCoordinator.setRootCoordinator(coordinator)
|
||||
}
|
||||
|
||||
private func startSpaceFlow(spaceRoomListProxy: SpaceRoomListProxyProtocol) {
|
||||
let coordinator = SpaceFlowCoordinator(spaceRoomListProxy: spaceRoomListProxy,
|
||||
spaceServiceProxy: userSession.clientProxy.spaceService,
|
||||
isChildFlow: false,
|
||||
mediaProvider: userSession.mediaProvider,
|
||||
navigationStackCoordinator: detailNavigationStackCoordinator,
|
||||
userIndicatorController: userIndicatorController)
|
||||
|
||||
coordinator.actionsPublisher
|
||||
.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .finished:
|
||||
stateMachine.tryEvent(.deselectSpace)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
spaceFlowCoordinator = coordinator
|
||||
|
||||
if navigationSplitCoordinator.detailCoordinator !== detailNavigationStackCoordinator {
|
||||
navigationSplitCoordinator.setDetailCoordinator(detailNavigationStackCoordinator)
|
||||
}
|
||||
|
||||
coordinator.start()
|
||||
selectedSpaceSubject.send(spaceRoomListProxy.spaceRoom.id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
//
|
||||
// Copyright 2025 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
import SwiftState
|
||||
|
||||
enum SpaceFlowCoordinatorAction: Equatable {
|
||||
case finished
|
||||
}
|
||||
|
||||
class SpaceFlowCoordinator: FlowCoordinatorProtocol {
|
||||
private let spaceRoomListProxy: SpaceRoomListProxyProtocol
|
||||
private let spaceServiceProxy: SpaceServiceProxyProtocol
|
||||
private let isChildFlow: Bool
|
||||
|
||||
private let mediaProvider: MediaProviderProtocol
|
||||
|
||||
private let navigationStackCoordinator: NavigationStackCoordinator
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private var childSpaceFlowCoordinator: SpaceFlowCoordinator?
|
||||
|
||||
indirect enum State: StateType {
|
||||
/// The state machine hasn't started.
|
||||
case initial
|
||||
/// The root screen for this flow.
|
||||
case space
|
||||
/// A child flow is in progress.
|
||||
case presentingChild(childSpaceID: String, previousState: State)
|
||||
}
|
||||
|
||||
enum Event: EventType {
|
||||
/// The flow is being started.
|
||||
case start
|
||||
|
||||
/// Request the presentation of a child space flow.
|
||||
///
|
||||
/// The space's `SpaceRoomListProxyProtocol` must be provided in the `userInfo`.
|
||||
case startChildFlow
|
||||
/// Tidy-up the child flow after it has dismissed itself.
|
||||
case stopChildFlow
|
||||
}
|
||||
|
||||
private let stateMachine: StateMachine<State, Event>
|
||||
private var cancellables: Set<AnyCancellable> = []
|
||||
|
||||
private let actionsSubject: PassthroughSubject<SpaceFlowCoordinatorAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<SpaceFlowCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(spaceRoomListProxy: SpaceRoomListProxyProtocol,
|
||||
spaceServiceProxy: SpaceServiceProxyProtocol,
|
||||
isChildFlow: Bool,
|
||||
mediaProvider: MediaProviderProtocol,
|
||||
navigationStackCoordinator: NavigationStackCoordinator,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.spaceRoomListProxy = spaceRoomListProxy
|
||||
self.spaceServiceProxy = spaceServiceProxy
|
||||
self.isChildFlow = isChildFlow
|
||||
|
||||
self.mediaProvider = mediaProvider
|
||||
|
||||
self.navigationStackCoordinator = navigationStackCoordinator
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
stateMachine = .init(state: .initial)
|
||||
configureStateMachine()
|
||||
}
|
||||
|
||||
func start() {
|
||||
stateMachine.tryEvent(.start)
|
||||
}
|
||||
|
||||
func handleAppRoute(_ appRoute: AppRoute, animated: Bool) {
|
||||
// There aren't any routes to this screen yet, so clear the stacks.
|
||||
clearRoute(animated: animated)
|
||||
}
|
||||
|
||||
func clearRoute(animated: Bool) {
|
||||
switch stateMachine.state {
|
||||
case .initial:
|
||||
break
|
||||
case .space:
|
||||
if isChildFlow {
|
||||
navigationStackCoordinator.pop(animated: animated)
|
||||
} else {
|
||||
navigationStackCoordinator.setRootCoordinator(nil, animated: animated)
|
||||
}
|
||||
case .presentingChild:
|
||||
childSpaceFlowCoordinator?.clearRoute(animated: animated)
|
||||
clearRoute(animated: animated) // Re-run with the state machine back in the .space state.
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func configureStateMachine() {
|
||||
stateMachine.addRoutes(event: .start, transitions: [.initial => .space]) { [weak self] _ in
|
||||
self?.presentSpace()
|
||||
}
|
||||
|
||||
stateMachine.addRouteMapping { event, fromState, userInfo in
|
||||
guard event == .startChildFlow, case .space = fromState else { return nil }
|
||||
guard let spaceRoomListProxy = userInfo as? SpaceRoomListProxyProtocol else { fatalError("A space proxy must be provided.") }
|
||||
return .presentingChild(childSpaceID: spaceRoomListProxy.spaceRoom.id, previousState: fromState)
|
||||
} handler: { [weak self] context in
|
||||
guard let self, let spaceRoomListProxy = context.userInfo as? SpaceRoomListProxyProtocol else { return }
|
||||
startChildFlow(for: spaceRoomListProxy)
|
||||
}
|
||||
|
||||
stateMachine.addRouteMapping { event, fromState, _ in
|
||||
guard event == .stopChildFlow, case .presentingChild(_, let previousState) = fromState else { return nil }
|
||||
return previousState
|
||||
} handler: { [weak self] _ in
|
||||
guard let self else { return }
|
||||
childSpaceFlowCoordinator = nil
|
||||
}
|
||||
|
||||
stateMachine.addErrorHandler { context in
|
||||
fatalError("Unexpected transition: \(context)")
|
||||
}
|
||||
}
|
||||
|
||||
private func presentSpace() {
|
||||
let parameters = SpaceScreenCoordinatorParameters(spaceRoomListProxy: spaceRoomListProxy,
|
||||
spaceServiceProxy: spaceServiceProxy,
|
||||
mediaProvider: mediaProvider,
|
||||
userIndicatorController: userIndicatorController)
|
||||
let coordinator = SpaceScreenCoordinator(parameters: parameters)
|
||||
coordinator.actionsPublisher
|
||||
.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .selectSpace(let spaceRoomListProxy):
|
||||
stateMachine.tryEvent(.startChildFlow, userInfo: spaceRoomListProxy)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
if isChildFlow {
|
||||
navigationStackCoordinator.push(coordinator) { [weak self] in
|
||||
self?.actionsSubject.send(.finished)
|
||||
}
|
||||
} else {
|
||||
navigationStackCoordinator.setRootCoordinator(coordinator) { [weak self] in
|
||||
self?.actionsSubject.send(.finished)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Other flows
|
||||
|
||||
private func startChildFlow(for spaceRoomListProxy: SpaceRoomListProxyProtocol) {
|
||||
let coordinator = SpaceFlowCoordinator(spaceRoomListProxy: spaceRoomListProxy,
|
||||
spaceServiceProxy: spaceServiceProxy,
|
||||
isChildFlow: true,
|
||||
mediaProvider: mediaProvider,
|
||||
navigationStackCoordinator: navigationStackCoordinator,
|
||||
userIndicatorController: userIndicatorController)
|
||||
|
||||
coordinator.actionsPublisher
|
||||
.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .finished:
|
||||
stateMachine.tryEvent(.stopChildFlow)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
childSpaceFlowCoordinator = coordinator
|
||||
coordinator.start()
|
||||
}
|
||||
}
|
||||
@@ -271,7 +271,8 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
|
||||
.store(in: &cancellables)
|
||||
|
||||
appSettings.$spacesEnabled
|
||||
.map { $0 ? .automatic : .hidden }
|
||||
.combineLatest(userSession.clientProxy.spaceService.joinedSpacesPublisher)
|
||||
.map { $0 && !$1.isEmpty ? .automatic : .hidden }
|
||||
.weakAssign(to: \.chatsTabDetails.barVisibility, on: self)
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
@@ -85,6 +85,8 @@ extension ClientProxyMock {
|
||||
secureBackupController = SecureBackupControllerMock(.init(recoveryState: configuration.recoveryState))
|
||||
resetIdentityReturnValue = .success(IdentityResetHandleSDKMock(.init()))
|
||||
|
||||
spaceService = SpaceServiceProxyMock(.init())
|
||||
|
||||
roomForIdentifierClosure = { [weak self] identifier in
|
||||
guard let room = self?.roomSummaryProvider.roomListPublisher.value.first(where: { $0.id == identifier }) else {
|
||||
return nil
|
||||
|
||||
@@ -2156,6 +2156,11 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
|
||||
}
|
||||
var underlyingSecureBackupController: SecureBackupControllerProtocol!
|
||||
var sessionVerificationController: SessionVerificationControllerProxyProtocol?
|
||||
var spaceService: SpaceServiceProxyProtocol {
|
||||
get { return underlyingSpaceService }
|
||||
set(value) { underlyingSpaceService = value }
|
||||
}
|
||||
var underlyingSpaceService: SpaceServiceProxyProtocol!
|
||||
var isReportRoomSupportedCallsCount = 0
|
||||
var isReportRoomSupportedCalled: Bool {
|
||||
return isReportRoomSupportedCallsCount > 0
|
||||
|
||||
@@ -99,6 +99,14 @@ extension [SpaceRoomProxyProtocol] {
|
||||
makeSpaceRooms(isSpace: true) + makeSpaceRooms(isSpace: false)
|
||||
}
|
||||
|
||||
static var mockSingleRoom: [SpaceRoomProxyProtocol] {
|
||||
[SpaceRoomProxyMock(.init(id: "!spaceroom:matrix.org",
|
||||
name: "Management",
|
||||
isSpace: false,
|
||||
joinedMembersCount: 12,
|
||||
topic: "This is where everything gets organised 📋."))]
|
||||
}
|
||||
|
||||
private static func makeSpaceRooms(isSpace: Bool) -> [SpaceRoomProxyMock] {
|
||||
let typeName = isSpace ? "Space" : "Room"
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
@@ -27,3 +28,16 @@ extension SpaceServiceProxyMock {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension SpaceServiceProxyMock.Configuration {
|
||||
static var populated: SpaceServiceProxyMock.Configuration {
|
||||
let spaceRoomLists = [SpaceRoomProxyProtocol].mockJoinedSpaces.map {
|
||||
($0.id, SpaceRoomListProxyMock(.init(spaceRoomProxy: $0, initialSpaceRooms: .mockSpaceList)))
|
||||
}
|
||||
let subSpaceRoomLists = [SpaceRoomProxyProtocol].mockSpaceList.map {
|
||||
($0.id, SpaceRoomListProxyMock(.init(spaceRoomProxy: $0, initialSpaceRooms: .mockSingleRoom)))
|
||||
}
|
||||
|
||||
return .init(joinedSpaces: .mockJoinedSpaces, spaceRoomLists: .init(uniqueKeysWithValues: spaceRoomLists + subSpaceRoomLists))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import SwiftUI
|
||||
struct SpaceRoomCell: View {
|
||||
@Environment(\.dynamicTypeSize) var dynamicTypeSize
|
||||
|
||||
let spaceRoom: SpaceRoomProxyProtocol
|
||||
let spaceRoomProxy: SpaceRoomProxyProtocol
|
||||
let isSelected: Bool
|
||||
let mediaProvider: MediaProviderProtocol!
|
||||
|
||||
@@ -23,25 +23,25 @@ struct SpaceRoomCell: View {
|
||||
private let horizontalInsets = 16.0
|
||||
|
||||
private var subtitle: String {
|
||||
if spaceRoom.isSpace {
|
||||
spaceRoom.joinRule == .public ? L10n.commonPublicSpace : L10n.commonPrivateSpace
|
||||
if spaceRoomProxy.isSpace {
|
||||
spaceRoomProxy.joinRule == .public ? L10n.commonPublicSpace : L10n.commonPrivateSpace
|
||||
} else {
|
||||
L10n.commonMemberCount(spaceRoom.joinedMembersCount)
|
||||
L10n.commonMemberCount(spaceRoomProxy.joinedMembersCount)
|
||||
}
|
||||
}
|
||||
|
||||
private var details: String {
|
||||
if spaceRoom.isSpace {
|
||||
L10n.screenSpaceListDetails(L10n.commonRooms(spaceRoom.childrenCount),
|
||||
L10n.commonMemberCount(spaceRoom.joinedMembersCount))
|
||||
if spaceRoomProxy.isSpace {
|
||||
L10n.screenSpaceListDetails(L10n.commonRooms(spaceRoomProxy.childrenCount),
|
||||
L10n.commonMemberCount(spaceRoomProxy.joinedMembersCount))
|
||||
} else {
|
||||
spaceRoom.topic ?? " " // Use a single space to reserve a consistent amount of space.
|
||||
spaceRoomProxy.topic ?? " " // Use a single space to reserve a consistent amount of space.
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
action(.select(spaceRoom))
|
||||
action(.select(spaceRoomProxy))
|
||||
} label: {
|
||||
HStack(spacing: 16.0) {
|
||||
avatar
|
||||
@@ -59,13 +59,13 @@ struct SpaceRoomCell: View {
|
||||
.accessibilityElement(children: .combine)
|
||||
}
|
||||
.buttonStyle(SpaceRoomCellButtonStyle(isSelected: isSelected))
|
||||
.accessibilityIdentifier(A11yIdentifiers.spaceListScreen.spaceRoomName(spaceRoom.name ?? spaceRoom.id))
|
||||
.accessibilityIdentifier(A11yIdentifiers.spaceListScreen.spaceRoomName(spaceRoomProxy.name ?? spaceRoomProxy.id))
|
||||
}
|
||||
|
||||
@ViewBuilder @MainActor
|
||||
private var avatar: some View {
|
||||
if dynamicTypeSize < .accessibility3 {
|
||||
RoomAvatarImage(avatar: spaceRoom.avatar,
|
||||
RoomAvatarImage(avatar: spaceRoomProxy.avatar,
|
||||
avatarSize: .room(on: .spaces),
|
||||
mediaProvider: mediaProvider)
|
||||
.dynamicTypeSize(dynamicTypeSize < .accessibility1 ? dynamicTypeSize : .accessibility1)
|
||||
@@ -76,7 +76,7 @@ struct SpaceRoomCell: View {
|
||||
private var content: some View {
|
||||
HStack(spacing: 16) {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(spaceRoom.name ?? spaceRoom.id)
|
||||
Text(spaceRoomProxy.name ?? spaceRoomProxy.id)
|
||||
.font(.compound.bodyLGSemibold)
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.lineLimit(1)
|
||||
@@ -101,7 +101,7 @@ struct SpaceRoomCell: View {
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
.lineLimit(1)
|
||||
} icon: {
|
||||
CompoundIcon(spaceRoom.joinRule == .public ? \.public : \.lockSolid,
|
||||
CompoundIcon(spaceRoomProxy.joinRule == .public ? \.public : \.lockSolid,
|
||||
size: .xSmall,
|
||||
relativeTo: .compound.bodyMD)
|
||||
.foregroundStyle(.compound.iconTertiary)
|
||||
@@ -111,9 +111,9 @@ struct SpaceRoomCell: View {
|
||||
|
||||
@ViewBuilder
|
||||
private var accessory: some View {
|
||||
switch spaceRoom.state {
|
||||
switch spaceRoomProxy.state {
|
||||
case .none, .left, .invited:
|
||||
Button(L10n.actionJoin) { action(.join(spaceRoom)) }
|
||||
Button(L10n.actionJoin) { action(.join(spaceRoomProxy)) }
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textActionAccent)
|
||||
case .joined, .knocked, .banned:
|
||||
@@ -141,7 +141,7 @@ struct SpaceRoomCell_Previews: PreviewProvider, TestablePreview {
|
||||
static var previews: some View {
|
||||
VStack(spacing: 0) {
|
||||
ForEach(spaces, id: \.id) { space in
|
||||
SpaceRoomCell(spaceRoom: space,
|
||||
SpaceRoomCell(spaceRoomProxy: space,
|
||||
isSelected: false,
|
||||
mediaProvider: mediaProvider) { _ in }
|
||||
}
|
||||
|
||||
@@ -12,11 +12,12 @@ import SwiftUI
|
||||
|
||||
struct SpaceListScreenCoordinatorParameters {
|
||||
let userSession: UserSessionProtocol
|
||||
let spaceServiceProxy: SpaceServiceProxyProtocol
|
||||
let selectedSpaceSubject: CurrentValuePublisher<String?, Never>
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
}
|
||||
|
||||
enum SpaceListScreenCoordinatorAction {
|
||||
case selectSpace(SpaceRoomProxyProtocol)
|
||||
case selectSpace(SpaceRoomListProxyProtocol)
|
||||
case showSettings
|
||||
}
|
||||
|
||||
@@ -35,7 +36,8 @@ final class SpaceListScreenCoordinator: CoordinatorProtocol {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = SpaceListScreenViewModel(userSession: parameters.userSession,
|
||||
spaceServiceProxy: parameters.spaceServiceProxy)
|
||||
selectedSpaceSubject: parameters.selectedSpaceSubject,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
}
|
||||
|
||||
func start() {
|
||||
@@ -44,8 +46,8 @@ final class SpaceListScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .selectSpace(let spaceRoom):
|
||||
actionsSubject.send(.selectSpace(spaceRoom))
|
||||
case .selectSpace(let spaceRoomListProxy):
|
||||
actionsSubject.send(.selectSpace(spaceRoomListProxy))
|
||||
case .showSettings:
|
||||
actionsSubject.send(.showSettings)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import Foundation
|
||||
|
||||
enum SpaceListScreenViewModelAction {
|
||||
case selectSpace(SpaceRoomProxyProtocol)
|
||||
case selectSpace(SpaceRoomListProxyProtocol)
|
||||
case showSettings
|
||||
}
|
||||
|
||||
@@ -18,13 +18,17 @@ struct SpaceListScreenViewState: BindableState {
|
||||
var userAvatarURL: URL?
|
||||
|
||||
var joinedSpaces: [SpaceRoomProxyProtocol]
|
||||
var joinedRoomsCount: Int
|
||||
var selectedSpaceID: String?
|
||||
|
||||
var bindings: SpaceListScreenViewStateBindings
|
||||
|
||||
var subtitle: String {
|
||||
L10n.screenSpaceListDetails(L10n.commonSpaces(joinedSpaces.count), L10n.commonRooms(joinedRoomsCount))
|
||||
}
|
||||
|
||||
var joinedRoomsCount: Int {
|
||||
joinedSpaces.map(\.childrenCount).reduce(0, +)
|
||||
}
|
||||
}
|
||||
|
||||
struct SpaceListScreenViewStateBindings { }
|
||||
|
||||
@@ -12,18 +12,21 @@ typealias SpaceListScreenViewModelType = StateStoreViewModelV2<SpaceListScreenVi
|
||||
|
||||
class SpaceListScreenViewModel: SpaceListScreenViewModelType, SpaceListScreenViewModelProtocol {
|
||||
private let spaceServiceProxy: SpaceServiceProxyProtocol
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<SpaceListScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<SpaceListScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(userSession: UserSessionProtocol, spaceServiceProxy: SpaceServiceProxyProtocol) {
|
||||
self.spaceServiceProxy = spaceServiceProxy
|
||||
init(userSession: UserSessionProtocol,
|
||||
selectedSpaceSubject: CurrentValuePublisher<String?, Never>,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
spaceServiceProxy = userSession.clientProxy.spaceService
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
super.init(initialViewState: SpaceListScreenViewState(userID: userSession.clientProxy.userID,
|
||||
joinedSpaces: spaceServiceProxy.joinedSpacesPublisher.value,
|
||||
joinedRoomsCount: 0,
|
||||
bindings: .init()),
|
||||
mediaProvider: userSession.mediaProvider)
|
||||
|
||||
@@ -32,6 +35,10 @@ class SpaceListScreenViewModel: SpaceListScreenViewModelType, SpaceListScreenVie
|
||||
.weakAssign(to: \.state.joinedSpaces, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
selectedSpaceSubject
|
||||
.weakAssign(to: \.state.selectedSpaceID, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
userSession.clientProxy.userAvatarURLPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.userAvatarURL, on: self)
|
||||
@@ -49,12 +56,35 @@ class SpaceListScreenViewModel: SpaceListScreenViewModelType, SpaceListScreenVie
|
||||
MXLog.info("View model: received view action: \(viewAction)")
|
||||
|
||||
switch viewAction {
|
||||
case .spaceAction(.select(let spaceRoom)):
|
||||
actionsSubject.send(.selectSpace(spaceRoom))
|
||||
case .spaceAction(.select(let spaceRoomProxy)):
|
||||
Task { await selectSpace(spaceRoomProxy) }
|
||||
case .spaceAction(.join(let spaceRoom)):
|
||||
#warning("Implement joining.")
|
||||
case .showSettings:
|
||||
actionsSubject.send(.showSettings)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func selectSpace(_ spaceRoomProxy: SpaceRoomProxyProtocol) async {
|
||||
switch await spaceServiceProxy.spaceRoomList(for: spaceRoomProxy) {
|
||||
case .success(let spaceRoomListProxy):
|
||||
actionsSubject.send(.selectSpace(spaceRoomListProxy))
|
||||
case .failure(let error):
|
||||
MXLog.error("Unable to select space: \(error)")
|
||||
showFailureIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Indicators
|
||||
|
||||
private static var failureIndicatorID: String { "\(Self.self)-Failure" }
|
||||
|
||||
private func showFailureIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.failureIndicatorID,
|
||||
type: .toast,
|
||||
title: L10n.errorUnknown,
|
||||
iconName: "xmark"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ struct SpaceListScreen: View {
|
||||
|
||||
var spaces: some View {
|
||||
ForEach(context.viewState.joinedSpaces, id: \.id) { spaceRoom in
|
||||
SpaceRoomCell(spaceRoom: spaceRoom,
|
||||
isSelected: false,
|
||||
SpaceRoomCell(spaceRoomProxy: spaceRoom,
|
||||
isSelected: spaceRoom.id == context.viewState.selectedSpaceID,
|
||||
mediaProvider: context.mediaProvider) { action in
|
||||
context.send(viewAction: .spaceAction(action))
|
||||
}
|
||||
@@ -102,12 +102,13 @@ struct SpaceListScreen_Previews: PreviewProvider, TestablePreview {
|
||||
}
|
||||
}
|
||||
|
||||
static func makeViewModel(counterValue: Int = 0) -> SpaceListScreenViewModel {
|
||||
static func makeViewModel() -> SpaceListScreenViewModel {
|
||||
let clientProxy = ClientProxyMock(.init())
|
||||
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
|
||||
let spaceService = SpaceServiceProxyMock(.init(joinedSpaces: .mockJoinedSpaces))
|
||||
clientProxy.spaceService = SpaceServiceProxyMock(.init(joinedSpaces: .mockJoinedSpaces))
|
||||
|
||||
let viewModel = SpaceListScreenViewModel(userSession: userSession, spaceServiceProxy: spaceService)
|
||||
let viewModel = SpaceListScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxy)),
|
||||
selectedSpaceSubject: .init(nil),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
return viewModel
|
||||
}
|
||||
|
||||
@@ -12,11 +12,13 @@ import SwiftUI
|
||||
|
||||
struct SpaceScreenCoordinatorParameters {
|
||||
let spaceRoomListProxy: SpaceRoomListProxyProtocol
|
||||
let spaceServiceProxy: SpaceServiceProxyProtocol
|
||||
let mediaProvider: MediaProviderProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
}
|
||||
|
||||
enum SpaceScreenCoordinatorAction {
|
||||
case selectSpace(SpaceRoomProxyProtocol)
|
||||
case selectSpace(SpaceRoomListProxyProtocol)
|
||||
}
|
||||
|
||||
final class SpaceScreenCoordinator: CoordinatorProtocol {
|
||||
@@ -33,7 +35,10 @@ final class SpaceScreenCoordinator: CoordinatorProtocol {
|
||||
init(parameters: SpaceScreenCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = SpaceScreenViewModel(spaceRoomList: parameters.spaceRoomListProxy, mediaProvider: parameters.mediaProvider)
|
||||
viewModel = SpaceScreenViewModel(spaceRoomList: parameters.spaceRoomListProxy,
|
||||
spaceServiceProxy: parameters.spaceServiceProxy,
|
||||
mediaProvider: parameters.mediaProvider,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
}
|
||||
|
||||
func start() {
|
||||
@@ -42,8 +47,8 @@ final class SpaceScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .selectSpace(let spaceRoom):
|
||||
actionsSubject.send(.selectSpace(spaceRoom))
|
||||
case .selectSpace(let spaceRoomListProxy):
|
||||
actionsSubject.send(.selectSpace(spaceRoomListProxy))
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import Foundation
|
||||
|
||||
enum SpaceScreenViewModelAction {
|
||||
case selectSpace(SpaceRoomProxyProtocol)
|
||||
case selectSpace(SpaceRoomListProxyProtocol)
|
||||
}
|
||||
|
||||
struct SpaceScreenViewState: BindableState {
|
||||
|
||||
@@ -11,12 +11,21 @@ import SwiftUI
|
||||
typealias SpaceScreenViewModelType = StateStoreViewModelV2<SpaceScreenViewState, SpaceScreenViewAction>
|
||||
|
||||
class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtocol {
|
||||
private let spaceServiceProxy: SpaceServiceProxyProtocol
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<SpaceScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<SpaceScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(spaceRoomList: SpaceRoomListProxyProtocol, mediaProvider: MediaProviderProtocol) {
|
||||
init(spaceRoomList: SpaceRoomListProxyProtocol,
|
||||
spaceServiceProxy: SpaceServiceProxyProtocol,
|
||||
mediaProvider: MediaProviderProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.spaceServiceProxy = spaceServiceProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
super.init(initialViewState: SpaceScreenViewState(space: spaceRoomList.spaceRoom,
|
||||
rooms: spaceRoomList.spaceRoomsPublisher.value),
|
||||
mediaProvider: mediaProvider)
|
||||
@@ -47,14 +56,37 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
MXLog.info("View model: received view action: \(viewAction)")
|
||||
|
||||
switch viewAction {
|
||||
case .spaceAction(.select(let spaceRoom)):
|
||||
if spaceRoom.isSpace {
|
||||
actionsSubject.send(.selectSpace(spaceRoom))
|
||||
case .spaceAction(.select(let spaceRoomProxy)):
|
||||
if spaceRoomProxy.isSpace {
|
||||
Task { await selectSpace(spaceRoomProxy) }
|
||||
} else {
|
||||
#warning("Implement joining")
|
||||
#warning("Implement room flow")
|
||||
}
|
||||
case .spaceAction(.join(let spaceID)):
|
||||
#warning("Implement joining.")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func selectSpace(_ spaceRoomProxy: SpaceRoomProxyProtocol) async {
|
||||
switch await spaceServiceProxy.spaceRoomList(for: spaceRoomProxy) {
|
||||
case .success(let spaceRoomListProxy):
|
||||
actionsSubject.send(.selectSpace(spaceRoomListProxy))
|
||||
case .failure(let error):
|
||||
MXLog.error("Unable to select space: \(error)")
|
||||
showFailureIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Indicators
|
||||
|
||||
private static var failureIndicatorID: String { "\(Self.self)-Failure" }
|
||||
|
||||
private func showFailureIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.failureIndicatorID,
|
||||
type: .toast,
|
||||
title: L10n.errorUnknown,
|
||||
iconName: "xmark"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ struct SpaceScreen: View {
|
||||
|
||||
@ViewBuilder
|
||||
var rooms: some View {
|
||||
ForEach(context.viewState.rooms, id: \.id) { spaceRoom in
|
||||
SpaceRoomCell(spaceRoom: spaceRoom,
|
||||
ForEach(context.viewState.rooms, id: \.id) { spaceRoomProxy in
|
||||
SpaceRoomCell(spaceRoomProxy: spaceRoomProxy,
|
||||
isSelected: false,
|
||||
mediaProvider: context.mediaProvider) { action in
|
||||
context.send(viewAction: .spaceAction(action))
|
||||
@@ -65,7 +65,9 @@ struct SpaceScreen_Previews: PreviewProvider, TestablePreview {
|
||||
initialSpaceRooms: .mockSpaceList))
|
||||
|
||||
let viewModel = SpaceScreenViewModel(spaceRoomList: spaceRoomListProxy,
|
||||
mediaProvider: MediaProviderMock(configuration: .init()))
|
||||
spaceServiceProxy: SpaceServiceProxyMock(.init()),
|
||||
mediaProvider: MediaProviderMock(configuration: .init()),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
return viewModel
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ class ClientProxy: ClientProxyProtocol {
|
||||
|
||||
private(set) var sessionVerificationController: SessionVerificationControllerProxyProtocol?
|
||||
|
||||
let spaceService: SpaceServiceProxyProtocol
|
||||
|
||||
private static var roomCreationPowerLevelOverrides: PowerLevels {
|
||||
.init(usersDefault: nil,
|
||||
eventsDefault: nil,
|
||||
@@ -164,6 +166,10 @@ class ClientProxy: ClientProxyProtocol {
|
||||
|
||||
secureBackupController = SecureBackupController(encryption: client.encryption())
|
||||
|
||||
// Temporarily using the mock until the SDK is updated.
|
||||
// spaceService = SpaceServiceProxy(spaceService: client.spaceService())
|
||||
spaceService = SpaceServiceProxyMock(.init())
|
||||
|
||||
let configuredAppService = try await ClientProxyServices(client: client,
|
||||
actionsSubject: actionsSubject,
|
||||
notificationSettings: notificationSettings,
|
||||
|
||||
@@ -121,6 +121,8 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||
|
||||
var sessionVerificationController: SessionVerificationControllerProxyProtocol? { get }
|
||||
|
||||
var spaceService: SpaceServiceProxyProtocol { get }
|
||||
|
||||
var isReportRoomSupported: Bool { get async }
|
||||
|
||||
var isLiveKitRTCSupported: Bool { get async }
|
||||
|
||||
@@ -577,14 +577,19 @@ class MockScreen: Identifiable {
|
||||
appSettings: ServiceLocator.shared.settings,
|
||||
mediaProvider: MediaProviderMock(configuration: .init()))
|
||||
return SessionVerificationScreenCoordinator(parameters: parameters)
|
||||
case .userSessionScreen, .userSessionScreenReply:
|
||||
case .userSessionScreen, .userSessionScreenReply, .userSessionSpacesFlow:
|
||||
let appSettings: AppSettings = ServiceLocator.shared.settings
|
||||
appSettings.hasRunIdentityConfirmationOnboarding = true
|
||||
appSettings.hasRunNotificationPermissionsOnboarding = true
|
||||
appSettings.analyticsConsentState = .optedOut
|
||||
appSettings.spacesEnabled = true
|
||||
|
||||
let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com", deviceID: "MOCKCLIENT", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms)))))
|
||||
|
||||
// The tab bar remains hidden for the non-spaces tests as we don't supply any mock spaces.
|
||||
let spaceServiceProxy = SpaceServiceProxyMock(id == .userSessionSpacesFlow ? .populated : .init())
|
||||
clientProxy.spaceService = spaceServiceProxy
|
||||
|
||||
let appMediator = AppMediatorMock.default
|
||||
appMediator.underlyingWindowManager = windowManager
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ enum UITestsScreenIdentifier: String {
|
||||
case startChatWithSearchResults
|
||||
case userSessionScreen
|
||||
case userSessionScreenReply
|
||||
case userSessionSpacesFlow
|
||||
case autoUpdatingTimeline
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user