Make sure the selected/available rooms are updated when adding space children fails part way through. (#4997)

* Make sure the available rooms are updated if adding space children fails part way through.

* Additionally handle the case where removing rooms fails part way through.
This commit is contained in:
Doug
2026-01-23 17:36:26 +00:00
committed by GitHub
parent a3683ea996
commit 3b231339cd
6 changed files with 125 additions and 12 deletions
@@ -156,6 +156,7 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
case .finishManagingChildren:
withAnimation(.easeOut(duration: 0.25).disabledDuringTests()) {
state.editMode = .inactive
state.editModeRemovedIDs = []
} completion: {
self.state.editModeSelectedIDs.removeAll()
}
@@ -209,16 +210,27 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
state.bindings.isPresentingRemoveChildrenConfirmation = false
MXLog.info("Removing \(state.editModeSelectedIDs.count) children from space \(spaceRoomListProxy.id)")
var removedIDs: [String] = [] // Using an intermediate array so the screen doesn't change until the operation finishes.
for childID in state.editModeSelectedIDs {
switch await spaceServiceProxy.removeChild(childID, from: spaceRoomListProxy.id) {
case .success:
MXLog.info("Successfully removed \(childID) from \(spaceRoomListProxy.id)")
case .failure:
removedIDs.append(childID)
case .failure(let error):
MXLog.error("Failed removing room from space: \(error)")
showFailureIndicator()
// Hide rooms that were successfully removed.
state.editModeSelectedIDs = state.editModeSelectedIDs.filter { !removedIDs.contains($0) }
state.editModeRemovedIDs.formUnion(removedIDs)
return
}
}
MXLog.info("\(state.editModeSelectedIDs.count) children removed from space \(spaceRoomListProxy.id)")
await spaceRoomListProxy.resetAndWaitForFullReload(timeout: .seconds(10))
process(viewAction: .finishManagingChildren)