From 9cbc2921e32bfc30c50b3696ab0a449cae30a5c7 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 18 May 2021 16:42:08 +1000 Subject: [PATCH] fix move-insert conflict --- Session/Home/HomeVC.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift index 20a70778f..2808e224f 100644 --- a/Session/Home/HomeVC.swift +++ b/Session/Home/HomeVC.swift @@ -226,12 +226,26 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv switch rowChange.type { case .delete: tableView.deleteRows(at: [ rowChange.indexPath! ], with: UITableView.RowAnimation.automatic) case .insert: tableView.insertRows(at: [ rowChange.newIndexPath! ], with: UITableView.RowAnimation.automatic) - case .move: tableView.moveRow(at: rowChange.indexPath!, to: rowChange.newIndexPath!) case .update: tableView.reloadRows(at: [ rowChange.indexPath! ], with: UITableView.RowAnimation.automatic) default: break } } tableView.endUpdates() + // HACK: Moves can have conflicts with other 3 types of change. + // Just batch perform all the moves seperately to prevent crashing. + // Since all the changes are from original state to final state, + // it will still be correct if we pick the Moves out. + tableView.beginUpdates() + rowChanges.forEach { rowChange in + let rowChange = rowChange as! YapDatabaseViewRowChange + let key = rowChange.collectionKey.key + threadViewModelCache[key] = nil + switch rowChange.type { + case .move: tableView.moveRow(at: rowChange.indexPath!, to: rowChange.newIndexPath!) + default: break + } + } + tableView.endUpdates() emptyStateView.isHidden = (threadCount != 0) }