mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
pr suggestions + await PLs of the room to be ready before adding it to the space
This commit is contained in:
@@ -282,10 +282,8 @@ class CreateRoomScreenViewModel: CreateRoomScreenViewModelType, CreateRoomScreen
|
||||
}
|
||||
}
|
||||
|
||||
if let selectedSpace = state.bindings.selectedSpace,
|
||||
case .failure = await userSession.clientProxy.spaceService.addChild(roomID, to: selectedSpace.id) {
|
||||
MXLog.error("Failed to add the created room with id: \(roomID) to the space with id: \(selectedSpace.id)")
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
if let spaceID = state.bindings.selectedSpace?.id {
|
||||
await addRoomToSpace(roomProxy: roomProxy, spaceID: spaceID)
|
||||
}
|
||||
|
||||
actionsSubject.send(.createdRoom(roomProxy, spaceRoomListProxy))
|
||||
@@ -296,6 +294,25 @@ class CreateRoomScreenViewModel: CreateRoomScreenViewModelType, CreateRoomScreen
|
||||
}
|
||||
}
|
||||
|
||||
private func addRoomToSpace(roomProxy: JoinedRoomProxyProtocol, spaceID: String) async {
|
||||
roomProxy.subscribeToRoomInfoUpdates()
|
||||
let runner = ExpiringTaskRunner {
|
||||
// Necessary to build the room cache so that the space can be added as a parent.
|
||||
_ = await roomProxy.infoPublisher.values.first { $0.powerLevels != nil }
|
||||
}
|
||||
|
||||
do {
|
||||
try await runner.run(timeout: .seconds(30))
|
||||
if case .failure = await userSession.clientProxy.spaceService.addChild(roomProxy.id, to: spaceID) {
|
||||
MXLog.error("Failed to add the created room with id: \(roomProxy.id) to the space with id: \(spaceID)")
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
} catch {
|
||||
MXLog.error("Timed out waiting for power levels to load for room with id: \(roomProxy.id)")
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Loading indicator
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(CreateRoomScreenViewModel.self)-Loading"
|
||||
|
||||
Reference in New Issue
Block a user