SpaceList: Fix a crash when clearing cache or logout.

This commit is contained in:
SBiOSoftWhare
2021-11-03 18:59:35 +01:00
parent 2a2f0fcfe9
commit 5c06b6dc2f
@@ -131,6 +131,9 @@ final class SpaceListViewModel: SpaceListViewModelType {
private func loadData() {
guard let session = self.userSessionsService.mainUserSession?.matrixSession else {
// If there is no main session, reset current selection and give an empty section list
// It can happen when the user make a clear cache or logout
self.resetList()
return
}
@@ -243,4 +246,15 @@ final class SpaceListViewModel: SpaceListViewModelType {
return spaceViewData.spaceId
}
}
private func resetList() {
self.sections = []
let selectedIndexPath = IndexPath(row: 0, section: 0)
self.selectedIndexPath = selectedIndexPath
self.homeIndexPath = selectedIndexPath
self.update(viewState: .loaded([]))
}
}