diff --git a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift index 164364e9f..4cd23ffdb 100644 --- a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift @@ -287,7 +287,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { } .store(in: &cancellables) - userSession.clientProxy.spaceService.joinedSpacesPublisher + userSession.clientProxy.spaceService.topLevelSpacesPublisher .map { $0.isEmpty ? .hidden : nil } .weakAssign(to: \.chatsTabDetails.barVisibilityOverride, on: self) .store(in: &cancellables) diff --git a/ElementX/Sources/Mocks/ClientProxyMock.swift b/ElementX/Sources/Mocks/ClientProxyMock.swift index 93311c049..f935f891d 100644 --- a/ElementX/Sources/Mocks/ClientProxyMock.swift +++ b/ElementX/Sources/Mocks/ClientProxyMock.swift @@ -121,7 +121,7 @@ extension ClientProxyMock { roomProxy.loadOrFetchEventDetailsForReturnValue = .success(TimelineEventSDKMock()) return .joined(roomProxy) } - } else if let spaceRoomProxy = configuration.spaceServiceConfiguration.joinedSpaces.first(where: { $0.id == identifier }) { + } else if let spaceRoomProxy = configuration.spaceServiceConfiguration.topLevelSpaces.first(where: { $0.id == identifier }) { let roomProxy = await JoinedRoomProxyMock(.init(id: spaceRoomProxy.id, name: spaceRoomProxy.name, isSpace: spaceRoomProxy.isSpace)) roomProxy.loadOrFetchEventDetailsForReturnValue = .success(TimelineEventSDKMock()) return .joined(roomProxy) diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index e790d0765..22f5f5d4b 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -16685,11 +16685,11 @@ class SpaceRoomProxyMock: SpaceRoomProxyProtocol, @unchecked Sendable { } class SpaceServiceProxyMock: SpaceServiceProxyProtocol, @unchecked Sendable { - var joinedSpacesPublisher: CurrentValuePublisher<[SpaceRoomProxyProtocol], Never> { - get { return underlyingJoinedSpacesPublisher } - set(value) { underlyingJoinedSpacesPublisher = value } + var topLevelSpacesPublisher: CurrentValuePublisher<[SpaceRoomProxyProtocol], Never> { + get { return underlyingTopLevelSpacesPublisher } + set(value) { underlyingTopLevelSpacesPublisher = value } } - var underlyingJoinedSpacesPublisher: CurrentValuePublisher<[SpaceRoomProxyProtocol], Never>! + var underlyingTopLevelSpacesPublisher: CurrentValuePublisher<[SpaceRoomProxyProtocol], Never>! //MARK: - spaceRoomList diff --git a/ElementX/Sources/Mocks/SpaceServiceProxyMock.swift b/ElementX/Sources/Mocks/SpaceServiceProxyMock.swift index d9d188bdb..26c78eebb 100644 --- a/ElementX/Sources/Mocks/SpaceServiceProxyMock.swift +++ b/ElementX/Sources/Mocks/SpaceServiceProxyMock.swift @@ -12,7 +12,7 @@ import MatrixRustSDK extension SpaceServiceProxyMock { struct Configuration { - var joinedSpaces: [SpaceRoomProxyProtocol] = [] + var topLevelSpaces: [SpaceRoomProxyProtocol] = [] var joinedParentSpaces: [SpaceRoomProxyProtocol] = [] var spaceRoomLists: [String: SpaceRoomListProxyMock] = [:] var leaveSpaceRooms: [LeaveSpaceRoom] = [] @@ -21,7 +21,7 @@ extension SpaceServiceProxyMock { convenience init(_ configuration: Configuration) { self.init() - joinedSpacesPublisher = .init(configuration.joinedSpaces) + topLevelSpacesPublisher = .init(configuration.topLevelSpaces) joinedParentsChildIDReturnValue = .success(configuration.joinedParentSpaces) spaceRoomListSpaceIDClosure = { spaceID in if let spaceRoomList = configuration.spaceRoomLists[spaceID] { @@ -35,7 +35,7 @@ extension SpaceServiceProxyMock { leaveHandle: LeaveSpaceHandleSDKMock(.init(rooms: configuration.leaveSpaceRooms)))) } spaceForIdentifierSpaceIDClosure = { spaceID in - .success(configuration.joinedSpaces.first { $0.id == spaceID }) + .success(configuration.topLevelSpaces.first { $0.id == spaceID }) } } } @@ -49,6 +49,6 @@ extension SpaceServiceProxyMock.Configuration { ($0.id, SpaceRoomListProxyMock(.init(spaceRoomProxy: $0, initialSpaceRooms: .mockSingleRoom))) } - return .init(joinedSpaces: .mockJoinedSpaces, spaceRoomLists: .init(uniqueKeysWithValues: spaceRoomLists + subSpaceRoomLists)) + return .init(topLevelSpaces: .mockJoinedSpaces, spaceRoomLists: .init(uniqueKeysWithValues: spaceRoomLists + subSpaceRoomLists)) } } diff --git a/ElementX/Sources/Screens/Spaces/SpaceListScreen/SpaceListScreenModels.swift b/ElementX/Sources/Screens/Spaces/SpaceListScreen/SpaceListScreenModels.swift index 60555c081..f76c999bc 100644 --- a/ElementX/Sources/Screens/Spaces/SpaceListScreen/SpaceListScreenModels.swift +++ b/ElementX/Sources/Screens/Spaces/SpaceListScreen/SpaceListScreenModels.swift @@ -18,7 +18,7 @@ struct SpaceListScreenViewState: BindableState { var userDisplayName: String? var userAvatarURL: URL? - var joinedSpaces: [SpaceRoomProxyProtocol] + var topLevelSpaces: [SpaceRoomProxyProtocol] var selectedSpaceID: String? var bindings: SpaceListScreenViewStateBindings diff --git a/ElementX/Sources/Screens/Spaces/SpaceListScreen/SpaceListScreenViewModel.swift b/ElementX/Sources/Screens/Spaces/SpaceListScreen/SpaceListScreenViewModel.swift index ed8e7ea45..b6f1e7fd1 100644 --- a/ElementX/Sources/Screens/Spaces/SpaceListScreen/SpaceListScreenViewModel.swift +++ b/ElementX/Sources/Screens/Spaces/SpaceListScreen/SpaceListScreenViewModel.swift @@ -30,13 +30,13 @@ class SpaceListScreenViewModel: SpaceListScreenViewModelType, SpaceListScreenVie self.userIndicatorController = userIndicatorController super.init(initialViewState: SpaceListScreenViewState(userID: userSession.clientProxy.userID, - joinedSpaces: spaceServiceProxy.joinedSpacesPublisher.value, + topLevelSpaces: spaceServiceProxy.topLevelSpacesPublisher.value, bindings: .init()), mediaProvider: userSession.mediaProvider) - spaceServiceProxy.joinedSpacesPublisher + spaceServiceProxy.topLevelSpacesPublisher .receive(on: DispatchQueue.main) - .weakAssign(to: \.state.joinedSpaces, on: self) + .weakAssign(to: \.state.topLevelSpaces, on: self) .store(in: &cancellables) selectedSpacePublisher diff --git a/ElementX/Sources/Screens/Spaces/SpaceListScreen/View/SpaceListScreen.swift b/ElementX/Sources/Screens/Spaces/SpaceListScreen/View/SpaceListScreen.swift index d08e62712..2d0ae87a6 100644 --- a/ElementX/Sources/Screens/Spaces/SpaceListScreen/View/SpaceListScreen.swift +++ b/ElementX/Sources/Screens/Spaces/SpaceListScreen/View/SpaceListScreen.swift @@ -40,7 +40,7 @@ struct SpaceListScreen: View { .foregroundStyle(.compound.textPrimary) .multilineTextAlignment(.center) - Text(L10n.commonSpaces(context.viewState.joinedSpaces.count)) + Text(L10n.commonSpaces(context.viewState.topLevelSpaces.count)) .font(.compound.bodyLG) .foregroundStyle(.compound.textSecondary) .multilineTextAlignment(.center) @@ -63,7 +63,7 @@ struct SpaceListScreen: View { } var spaces: some View { - ForEach(context.viewState.joinedSpaces, id: \.id) { spaceRoomProxy in + ForEach(context.viewState.topLevelSpaces, id: \.id) { spaceRoomProxy in SpaceRoomCell(spaceRoomProxy: spaceRoomProxy, isSelected: spaceRoomProxy.id == context.viewState.selectedSpaceID, mediaProvider: context.mediaProvider) { action in @@ -111,7 +111,7 @@ struct SpaceListScreen_Previews: PreviewProvider, TestablePreview { static func makeViewModel() -> SpaceListScreenViewModel { let clientProxy = ClientProxyMock(.init()) - clientProxy.spaceService = SpaceServiceProxyMock(.init(joinedSpaces: .mockJoinedSpaces)) + clientProxy.spaceService = SpaceServiceProxyMock(.init(topLevelSpaces: .mockJoinedSpaces)) let viewModel = SpaceListScreenViewModel(userSession: UserSessionMock(.init(clientProxy: clientProxy)), selectedSpacePublisher: .init(nil), diff --git a/ElementX/Sources/Services/Spaces/SpaceServiceProxy.swift b/ElementX/Sources/Services/Spaces/SpaceServiceProxy.swift index 4d4969855..6a275292b 100644 --- a/ElementX/Sources/Services/Spaces/SpaceServiceProxy.swift +++ b/ElementX/Sources/Services/Spaces/SpaceServiceProxy.swift @@ -13,9 +13,9 @@ import MatrixRustSDK class SpaceServiceProxy: SpaceServiceProxyProtocol { private let spaceService: SpaceServiceProtocol - private var joinedSpacesHandle: TaskHandle? + private var topLevelSpacesHandle: TaskHandle? private let spacesSubject = CurrentValueSubject<[SpaceRoomProxyProtocol], Never>([]) - var joinedSpacesPublisher: CurrentValuePublisher<[SpaceRoomProxyProtocol], Never> { + var topLevelSpacesPublisher: CurrentValuePublisher<[SpaceRoomProxyProtocol], Never> { spacesSubject.asCurrentValuePublisher() } @@ -26,7 +26,7 @@ class SpaceServiceProxy: SpaceServiceProxyProtocol { } private func setupSubscriptions() async { - joinedSpacesHandle = await spaceService.subscribeToTopLevelJoinedSpaces(listener: SDKListener { [weak self] updates in + topLevelSpacesHandle = await spaceService.subscribeToTopLevelJoinedSpaces(listener: SDKListener { [weak self] updates in self?.handleUpdates(updates) }) } diff --git a/ElementX/Sources/Services/Spaces/SpaceServiceProxyProtocol.swift b/ElementX/Sources/Services/Spaces/SpaceServiceProxyProtocol.swift index 624e548ed..830ef3fc1 100644 --- a/ElementX/Sources/Services/Spaces/SpaceServiceProxyProtocol.swift +++ b/ElementX/Sources/Services/Spaces/SpaceServiceProxyProtocol.swift @@ -15,7 +15,7 @@ enum SpaceServiceProxyError: Error { // sourcery: AutoMockable protocol SpaceServiceProxyProtocol { - var joinedSpacesPublisher: CurrentValuePublisher<[SpaceRoomProxyProtocol], Never> { get } + var topLevelSpacesPublisher: CurrentValuePublisher<[SpaceRoomProxyProtocol], Never> { get } func spaceRoomList(spaceID: String) async -> Result /// Returns a joined space given its identifier diff --git a/ElementX/Sources/UITests/UITestsAppCoordinator.swift b/ElementX/Sources/UITests/UITestsAppCoordinator.swift index dcd2ac1ea..95687b780 100644 --- a/ElementX/Sources/UITests/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITests/UITestsAppCoordinator.swift @@ -596,7 +596,7 @@ class MockScreen: Identifiable { let clientProxy = ClientProxyMock(.init(userID: "@mock:client.com", deviceID: "MOCKCLIENT", roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(roomSummaries))), - spaceServiceConfiguration: .init(joinedSpaces: .mockSingleRoom), + spaceServiceConfiguration: .init(topLevelSpaces: .mockSingleRoom), roomPreviews: [SpaceRoomProxyProtocol].mockSpaceList.map(RoomPreviewProxyMock.init))) // The tab bar remains hidden for the non-spaces tests as we don't supply any mock spaces. diff --git a/UnitTests/Sources/SecurityAndPrivacyScreenViewModelTests.swift b/UnitTests/Sources/SecurityAndPrivacyScreenViewModelTests.swift index f9814dc35..e35620f70 100644 --- a/UnitTests/Sources/SecurityAndPrivacyScreenViewModelTests.swift +++ b/UnitTests/Sources/SecurityAndPrivacyScreenViewModelTests.swift @@ -261,7 +261,7 @@ class SecurityAndPrivacyScreenViewModelTests: XCTestCase { let space = singleRoom[0] let allSpaces = joinedParentSpaces + singleRoom setupViewModel(joinedParentSpaces: joinedParentSpaces, - joinedSpaces: allSpaces, + topLevelSpaces: allSpaces, joinRule: .restricted(rules: [.roomMembership(roomId: space.id), .roomMembership(roomId: "unknownSpaceID")])) @@ -425,7 +425,7 @@ class SecurityAndPrivacyScreenViewModelTests: XCTestCase { // MARK: - Helpers private func setupViewModel(joinedParentSpaces: [SpaceRoomProxyProtocol], - joinedSpaces: [SpaceRoomProxyProtocol] = [], + topLevelSpaces: [SpaceRoomProxyProtocol] = [], joinRule: JoinRule) { let appSettings = AppSettings() appSettings.spaceSettingsEnabled = true @@ -440,7 +440,7 @@ class SecurityAndPrivacyScreenViewModelTests: XCTestCase { viewModel = SecurityAndPrivacyScreenViewModel(roomProxy: roomProxy, clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org", - spaceServiceConfiguration: .init(joinedSpaces: joinedSpaces, + spaceServiceConfiguration: .init(topLevelSpaces: topLevelSpaces, joinedParentSpaces: joinedParentSpaces))), userIndicatorController: UserIndicatorControllerMock(), appSettings: appSettings) diff --git a/UnitTests/Sources/SpaceListScreenViewModelTests.swift b/UnitTests/Sources/SpaceListScreenViewModelTests.swift index e6fc8ddae..37c59b8b2 100644 --- a/UnitTests/Sources/SpaceListScreenViewModelTests.swift +++ b/UnitTests/Sources/SpaceListScreenViewModelTests.swift @@ -13,7 +13,7 @@ import XCTest @MainActor class SpaceListScreenViewModelTests: XCTestCase { - var joinedSpacesSubject: CurrentValueSubject<[SpaceRoomProxyProtocol], Never>! + var topLevelSpacesSubject: CurrentValueSubject<[SpaceRoomProxyProtocol], Never>! var spaceServiceProxy: SpaceServiceProxyMock! var appSettings: AppSettings! @@ -34,29 +34,29 @@ class SpaceListScreenViewModelTests: XCTestCase { func testInitialState() { setupViewModel() - XCTAssertEqual(context.viewState.joinedSpaces.count, 3) + XCTAssertEqual(context.viewState.topLevelSpaces.count, 3) } - func testJoinedSpacesSubscription() async throws { + func testTopLevelSpacesSubscription() async throws { setupViewModel() - var deferred = deferFulfillment(context.observe(\.viewState.joinedSpaces)) { $0.count == 0 } - joinedSpacesSubject.send([]) + var deferred = deferFulfillment(context.observe(\.viewState.topLevelSpaces)) { $0.count == 0 } + topLevelSpacesSubject.send([]) try await deferred.fulfill() - XCTAssertEqual(context.viewState.joinedSpaces.count, 0) + XCTAssertEqual(context.viewState.topLevelSpaces.count, 0) - deferred = deferFulfillment(context.observe(\.viewState.joinedSpaces)) { $0.count == 1 } - joinedSpacesSubject.send([ + deferred = deferFulfillment(context.observe(\.viewState.topLevelSpaces)) { $0.count == 1 } + topLevelSpacesSubject.send([ SpaceRoomProxyMock(.init(isSpace: true)) ]) try await deferred.fulfill() - XCTAssertEqual(context.viewState.joinedSpaces.count, 1) + XCTAssertEqual(context.viewState.topLevelSpaces.count, 1) } func testSelectingSpace() async throws { setupViewModel() - let selectedSpace = joinedSpacesSubject.value[0] + let selectedSpace = topLevelSpacesSubject.value[0] let deferred = deferFulfillment(viewModel.actionsPublisher) { _ in true } viewModel.context.send(viewAction: .spaceAction(.select(selectedSpace))) let action = try await deferred.fulfill() @@ -96,15 +96,15 @@ class SpaceListScreenViewModelTests: XCTestCase { let clientProxy = ClientProxyMock(.init()) let userSession = UserSessionMock(.init(clientProxy: clientProxy)) - joinedSpacesSubject = .init([ + topLevelSpacesSubject = .init([ SpaceRoomProxyMock(.init(id: "space1", isSpace: true)), SpaceRoomProxyMock(.init(id: "space2", isSpace: true)), SpaceRoomProxyMock(.init(id: "space3", isSpace: true)) ]) spaceServiceProxy = SpaceServiceProxyMock(.init()) - spaceServiceProxy.joinedSpacesPublisher = joinedSpacesSubject.asCurrentValuePublisher() - spaceServiceProxy.spaceRoomListSpaceIDClosure = { [joinedSpacesSubject] spaceID in - guard let spaceRoomProxy = joinedSpacesSubject?.value.first(where: { $0.id == spaceID }) else { return .failure(.missingSpace) } + spaceServiceProxy.topLevelSpacesPublisher = topLevelSpacesSubject.asCurrentValuePublisher() + spaceServiceProxy.spaceRoomListSpaceIDClosure = { [topLevelSpacesSubject] spaceID in + guard let spaceRoomProxy = topLevelSpacesSubject?.value.first(where: { $0.id == spaceID }) else { return .failure(.missingSpace) } return .success(SpaceRoomListProxyMock(.init(spaceRoomProxy: spaceRoomProxy))) } clientProxy.spaceService = spaceServiceProxy