Refactor SpaceServiceProxy.joinedSpaces to topLevelSpaces.

This commit is contained in:
Doug
2026-01-05 15:35:11 +00:00
committed by Doug
parent 3cbeca82bd
commit 44f88adfb0
12 changed files with 39 additions and 39 deletions
@@ -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)
+1 -1
View File
@@ -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)
@@ -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
@@ -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))
}
}
@@ -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
@@ -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
@@ -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),
@@ -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)
})
}
@@ -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<SpaceRoomListProxyProtocol, SpaceServiceProxyError>
/// Returns a joined space given its identifier
@@ -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.