Avoid batch updates in updateLastViewedThread

This commit is contained in:
Sasha Weiss 2024-11-19 14:10:19 -08:00 committed by GitHub
parent 3175edfbf4
commit 20ce9381d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -43,8 +43,6 @@ public extension ChatListViewController {
// just-selected index path, so update the selection once more to
// reflect the loaded data.
ensureSelectedThread(thread, animated: animated)
tableView.scrollToNearestSelectedRow(at: .none, animated: animated)
}
/// Verifies that the currently selected cell matches the provided thread.
@ -62,15 +60,14 @@ public extension ChatListViewController {
let selectedIndexPath = selectedIndexPaths.first
let selectedThread = selectedIndexPath.flatMap(renderState.thread(forIndexPath:))
tableView.performBatchUpdates {
viewState.lastSelectedThreadId = targetThread.uniqueId
viewState.lastSelectedThreadId = targetThread.uniqueId
if let selectedIndexPath, selectedThread?.uniqueId != targetThread.uniqueId {
tableView.deselectRow(at: selectedIndexPath, animated: animated)
}
if let targetIndexPath = renderState.indexPath(forUniqueId: targetThread.uniqueId) {
tableView.selectRow(at: targetIndexPath, animated: animated, scrollPosition: .none)
if selectedThread?.uniqueId != targetThread.uniqueId {
if let targetPath = tableDataSource.renderState.indexPath(forUniqueId: targetThread.uniqueId) {
tableView.selectRow(at: targetPath, animated: animated, scrollPosition: .none)
tableView.scrollToRow(at: targetPath, at: .none, animated: animated)
} else if let stalePath = selectedIndexPath {
tableView.deselectRow(at: stalePath, animated: animated)
}
}
}