From f976d85c270800b627c476767a80ad860fe7ec20 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Mon, 3 Jul 2023 12:33:26 +1000 Subject: [PATCH] Fixed infinite loops introduced by the last change >_> --- .../MessageRequestsViewController.swift | 10 +++++++++- .../Shared/SessionTableViewController.swift | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Session/Home/Message Requests/MessageRequestsViewController.swift b/Session/Home/Message Requests/MessageRequestsViewController.swift index efc5f2e99..42cb93344 100644 --- a/Session/Home/Message Requests/MessageRequestsViewController.swift +++ b/Session/Home/Message Requests/MessageRequestsViewController.swift @@ -233,7 +233,15 @@ class MessageRequestsViewController: BaseVC, SessionUtilRespondingViewController // in from a frame of CGRect.zero) guard hasLoadedInitialThreadData else { UIView.performWithoutAnimation { - handleThreadUpdates(updatedData, changeset: changeset, initialLoad: true) + // Hide the 'loading conversations' label (now that we have received conversation data) + loadingConversationsLabel.isHidden = true + + // Show the empty state if there is no data + clearAllButton.isHidden = !(updatedData.first?.elements.isEmpty == false) + emptyStateLabel.isHidden = !clearAllButton.isHidden + + // Update the content + viewModel.updateThreadData(updatedData) tableView.reloadData() hasLoadedInitialThreadData = true } diff --git a/Session/Shared/SessionTableViewController.swift b/Session/Shared/SessionTableViewController.swift index 3f37f079c..5a825f5fc 100644 --- a/Session/Shared/SessionTableViewController.swift +++ b/Session/Shared/SessionTableViewController.swift @@ -224,22 +224,28 @@ class SessionTableViewController, initialLoad: Bool = false ) { + // Determine if we have any items for the empty state + let itemCount: Int = updatedData + .map { $0.elements.count } + .reduce(0, +) + // Ensure the first load runs without animations (if we don't do this the cells will animate // in from a frame of CGRect.zero) guard hasLoadedInitialTableData else { UIView.performWithoutAnimation { - handleDataUpdates(updatedData, changeset: changeset, initialLoad: true) + // Update the empty state + emptyStateLabel.isHidden = (itemCount > 0) + + // Update the content + viewModel.updateTableData(updatedData) tableView.reloadData() hasLoadedInitialTableData = true } return } - // Show the empty state if there is no data - let itemCount: Int = updatedData - .map { $0.elements.count } - .reduce(0, +) - emptyStateLabel.isHidden = (itemCount > 0) + // Update the empty state + self.emptyStateLabel.isHidden = (itemCount > 0) CATransaction.begin() CATransaction.setCompletionBlock { [weak self] in