@@ -198,8 +198,11 @@ final class ChatListViewController: KeyboardObservingViewController {
198198
199199 override func viewWillAppear( _ animated: Bool ) {
200200 super. viewWillAppear ( animated)
201- if let indexPath = tableView. indexPathForSelectedRow {
202- tableView. deselectRow ( at: indexPath, animated: animated)
201+
202+ if UIDevice . current. userInterfaceIdiom == . phone {
203+ if let indexPath = tableView. indexPathForSelectedRow {
204+ tableView. deselectRow ( at: indexPath, animated: animated)
205+ }
203206 }
204207 }
205208 override func viewDidLayoutSubviews( ) {
@@ -361,7 +364,7 @@ final class ChatListViewController: KeyboardObservingViewController {
361364
362365 private func updateUITitles( ) {
363366 updatingIndicatorView. updateTitle ( title: String . adamant. chatList. title)
364- tableView. reloadData ( )
367+ tableView. reloadDataPreservingSelection ( )
365368 searchController? . searchBar. placeholder = String . adamant. chatList. searchPlaceholder
366369 }
367370
@@ -412,7 +415,7 @@ final class ChatListViewController: KeyboardObservingViewController {
412415 areMessagesLoaded = true
413416 performOnMessagesLoadedActions ( )
414417 setIsBusy ( !synced)
415- tableView. reloadData ( )
418+ tableView. reloadDataPreservingSelection ( )
416419 }
417420
418421 // MARK: IB Actions
@@ -483,7 +486,7 @@ final class ChatListViewController: KeyboardObservingViewController {
483486
484487 switch result {
485488 case . success:
486- tableView. reloadData ( )
489+ tableView. reloadDataPreservingSelection ( )
487490 case . failure( let error) :
488491 dialogService. showRichError ( error: error)
489492 }
@@ -571,6 +574,7 @@ extension ChatListViewController: UITableViewDelegate, UITableViewDataSource {
571574 func tableView( _ tableView: UITableView , didDeselectRowAt indexPath: IndexPath ) {
572575 chatDeselectedIndex = indexPath
573576 }
577+
574578 func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
575579 if isBusy,
576580 indexPath. row == lastSystemChatPositionRow,
@@ -726,16 +730,15 @@ extension ChatListViewController {
726730
727731 private func insertReloadRow( ) {
728732 lastSystemChatPositionRow = getBottomSystemChatIndex ( )
729- tableView. reloadData ( )
733+ tableView. reloadDataPreservingSelection ( )
730734 }
731735
732736 @MainActor
733737 private func loadNewChats( offset: Int ) {
734738 loadNewChatTask = Task {
735739 await chatsProvider. getChatRooms ( offset: offset)
736740 isBusy = false
737- tableView. reloadData ( )
738- }
741+ tableView. reloadDataPreservingSelection ( ) }
739742 }
740743}
741744
@@ -1602,4 +1605,12 @@ private extension UITableView {
16021605 reloadRows ( at: indexPaths, with: . none)
16031606 selectRow ( at: selectedRowIndexPath, animated: false , scrollPosition: . none)
16041607 }
1608+
1609+ func reloadDataPreservingSelection( ) {
1610+ let selectedRow = indexPathForSelectedRow
1611+ reloadData ( )
1612+ if let selectedRow = selectedRow {
1613+ selectRow ( at: selectedRow, animated: false , scrollPosition: . none)
1614+ }
1615+ }
16051616}
0 commit comments