Fix crash when muting account (#245)

* Workaround crash when muting account

* Refactoring

Co-authored-by: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com>
This commit is contained in:
Thomas 2022-11-27 23:19:44 +01:00 committed by GitHub
parent b42dd286e6
commit 8692b8c9e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View File

@ -97,7 +97,11 @@ public class CollectionItemsViewModel: ObservableObject {
} }
// swiftlint:disable:next function_body_length cyclomatic_complexity // swiftlint:disable:next function_body_length cyclomatic_complexity
public func viewModel(indexPath: IndexPath) -> Any { public func viewModel(indexPath: IndexPath) -> Any? {
guard indexPath.section < lastUpdate.sections.count,
indexPath.item < lastUpdate.sections[indexPath.section].items.count
else { return nil }
let item = lastUpdate.sections[indexPath.section].items[indexPath.item] let item = lastUpdate.sections[indexPath.section].items[indexPath.item]
let cachedViewModel = viewModelCache[item] let cachedViewModel = viewModelCache[item]

View File

@ -22,7 +22,7 @@ public protocol CollectionViewModel {
func viewedAtTop(indexPath: IndexPath) func viewedAtTop(indexPath: IndexPath)
func select(indexPath: IndexPath) func select(indexPath: IndexPath)
func canSelect(indexPath: IndexPath) -> Bool func canSelect(indexPath: IndexPath) -> Bool
func viewModel(indexPath: IndexPath) -> Any func viewModel(indexPath: IndexPath) -> Any?
func toggleExpandAll() func toggleExpandAll()
func applyAccountListEdit(viewModel: AccountViewModel, edit: CollectionItemEvent.AccountListEdit) func applyAccountListEdit(viewModel: AccountViewModel, edit: CollectionItemEvent.AccountListEdit)
} }

View File

@ -178,7 +178,7 @@ extension ProfileViewModel: CollectionViewModel {
collectionViewModel.value.canSelect(indexPath: indexPath) collectionViewModel.value.canSelect(indexPath: indexPath)
} }
public func viewModel(indexPath: IndexPath) -> Any { public func viewModel(indexPath: IndexPath) -> Any? {
collectionViewModel.value.viewModel(indexPath: indexPath) collectionViewModel.value.viewModel(indexPath: indexPath)
} }