mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user