Add support for joining rooms from a space. (#4501)

* Add support for joining rooms from a space.

Doesn't yet handle the Join button 🤔

* Handle the join button for both rooms and spaces.

Also refactor more instances of spaceRoom to spaceRoomProxy.
This commit is contained in:
Doug
2025-09-11 16:41:19 +01:00
committed by GitHub
parent 880f2060f4
commit c2ac60f1e6
30 changed files with 304 additions and 34 deletions
@@ -12,6 +12,7 @@ typealias SpaceScreenViewModelType = StateStoreViewModelV2<SpaceScreenViewState,
class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtocol {
private let spaceServiceProxy: SpaceServiceProxyProtocol
private let clientProxy: ClientProxyProtocol
private let userIndicatorController: UserIndicatorControllerProtocol
private let actionsSubject: PassthroughSubject<SpaceScreenViewModelAction, Never> = .init()
@@ -22,15 +23,16 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
init(spaceRoomListProxy: SpaceRoomListProxyProtocol,
spaceServiceProxy: SpaceServiceProxyProtocol,
selectedSpaceRoomPublisher: CurrentValuePublisher<String?, Never>,
mediaProvider: MediaProviderProtocol,
userSession: UserSessionProtocol,
userIndicatorController: UserIndicatorControllerProtocol) {
self.spaceServiceProxy = spaceServiceProxy
clientProxy = userSession.clientProxy
self.userIndicatorController = userIndicatorController
super.init(initialViewState: SpaceScreenViewState(space: spaceRoomListProxy.spaceRoomProxy,
rooms: spaceRoomListProxy.spaceRoomsPublisher.value,
selectedSpaceRoomID: selectedSpaceRoomPublisher.value),
mediaProvider: mediaProvider)
mediaProvider: userSession.mediaProvider)
spaceRoomListProxy.spaceRoomsPublisher
.receive(on: DispatchQueue.main)
@@ -67,16 +69,20 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
case .spaceAction(.select(let spaceRoomProxy)):
if spaceRoomProxy.isSpace {
Task { await selectSpace(spaceRoomProxy) }
} else if spaceRoomProxy.state == .joined {
// This probably doesn't need the state condition as the room flow will show a join screen,
// but we can allow this later, once we've updated the design to indicate the parent space.
} else {
// No need to check the join state, the room flow will show an appropriately configured join screen if needed.
actionsSubject.send(.selectRoom(roomID: spaceRoomProxy.id))
}
case .spaceAction(.join(let spaceID)):
#warning("Implement joining.")
case .spaceAction(.join(let spaceRoomProxy)):
Task { await join(spaceRoomProxy) }
}
}
func stop() {
// If we pop this screen with running join operations, we don't want them to do anything.
state.joiningRoomIDs.removeAll()
}
// MARK: - Private
private func selectSpace(_ spaceRoomProxy: SpaceRoomProxyProtocol) async {
@@ -89,6 +95,25 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
}
}
private func join(_ spaceRoomProxy: SpaceRoomProxyProtocol) async {
state.joiningRoomIDs.insert(spaceRoomProxy.id)
defer { state.joiningRoomIDs.remove(spaceRoomProxy.id) }
guard case .success = await clientProxy.joinRoom(spaceRoomProxy.id, via: []) else {
showFailureIndicator()
return
}
// If multiple join operations are running, then only show the last one.
guard state.joiningRoomIDs == [spaceRoomProxy.id] else { return }
if spaceRoomProxy.isSpace {
await selectSpace(spaceRoomProxy)
} else {
actionsSubject.send(.selectRoom(roomID: spaceRoomProxy.id))
}
}
// MARK: - Indicators
private static var failureIndicatorID: String { "\(Self.self)-Failure" }