diff --git a/Mastodon/Scene/Account/AccountListViewModel.swift b/Mastodon/Scene/Account/AccountListViewModel.swift index f41133ad6..bf5c3f653 100644 --- a/Mastodon/Scene/Account/AccountListViewModel.swift +++ b/Mastodon/Scene/Account/AccountListViewModel.swift @@ -25,7 +25,6 @@ final class AccountListViewModel: NSObject { // output @Published var items: [Item] = [] - let dataSourceDidUpdate = PassthroughSubject() var diffableDataSource: UITableViewDiffableDataSource! init(context: AppContext, authContext: AuthContext) { @@ -50,9 +49,7 @@ final class AccountListViewModel: NSObject { snapshot.appendItems([.addAccount], toSection: .main) snapshot.appendItems([.logoutOfAllAccounts], toSection: .main) - diffableDataSource.apply(snapshot) { - self.dataSourceDidUpdate.send() - } + diffableDataSource.apply(snapshot) } .store(in: &disposeBag) } @@ -70,10 +67,7 @@ extension AccountListViewModel { case logoutOfAllAccounts } - func setupDiffableDataSource( - tableView: UITableView, - managedObjectContext: NSManagedObjectContext - ) { + func setupDiffableDataSource(tableView: UITableView) { diffableDataSource = UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item in switch item { case .authentication(let record): @@ -81,7 +75,6 @@ extension AccountListViewModel { if let activeAuthentication = AuthenticationServiceProvider.shared.authenticationSortedByActivation().first { AccountListViewModel.configure( - in: managedObjectContext, cell: cell, authentication: record, activeAuthentication: activeAuthentication @@ -103,7 +96,6 @@ extension AccountListViewModel { } static func configure( - in context: NSManagedObjectContext, cell: AccountListTableViewCell, authentication: MastodonAuthentication, activeAuthentication: MastodonAuthentication diff --git a/Mastodon/Scene/Account/AccountViewController.swift b/Mastodon/Scene/Account/AccountViewController.swift index f226c27ef..8bfa55ad4 100644 --- a/Mastodon/Scene/Account/AccountViewController.swift +++ b/Mastodon/Scene/Account/AccountViewController.swift @@ -76,26 +76,7 @@ extension AccountListViewController { ]) tableView.delegate = self - viewModel.setupDiffableDataSource( - tableView: tableView, - managedObjectContext: context.managedObjectContext - ) - - viewModel.dataSourceDidUpdate - .receive(on: DispatchQueue.main) - .sink { [weak self, weak presentingViewController] in - guard let self = self else { return } - - // the presentingViewController may deinit. - // Hold it and check the window to prevent PanModel crash - guard let _ = presentingViewController else { return } - guard self.view.window != nil else { return } - - self.hasLoaded = true - self.panModalSetNeedsLayoutUpdate() // <<< may crash the app - self.panModalTransition(to: .shortForm) - } - .store(in: &disposeBag) + viewModel.setupDiffableDataSource(tableView: tableView) } } @@ -117,8 +98,8 @@ extension AccountListViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) - guard let diffableDataSource = viewModel.diffableDataSource else { return } - guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return } + guard let diffableDataSource = viewModel.diffableDataSource, + let item = diffableDataSource.itemIdentifier(for: indexPath) else { return } switch item { case .authentication(let record):