diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index ef8d41622..eff6f4a58 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -903,7 +903,6 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers guard self.hasLoadedInitialInteractionData else { // Need to dispatch async to prevent this from causing glitches in the push animation DispatchQueue.main.async { - self.hasLoadedInitialInteractionData = true self.viewModel.updateInteractionData(updatedData) // Update the empty state @@ -911,6 +910,7 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers UIView.performWithoutAnimation { self.tableView.reloadData() + self.hasLoadedInitialInteractionData = true self.performInitialScrollIfNeeded() } } @@ -1218,7 +1218,11 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers } private func autoLoadNextPageIfNeeded() { - guard !self.isAutoLoadingNextPage && !self.isLoadingMore else { return } + guard + self.hasLoadedInitialInteractionData && + !self.isAutoLoadingNextPage && + !self.isLoadingMore + else { return } self.isAutoLoadingNextPage = true diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift index 5ddb4823c..bc524a220 100644 --- a/Session/Home/HomeVC.swift +++ b/Session/Home/HomeVC.swift @@ -409,8 +409,6 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData // 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 hasLoadedInitialThreadData else { - hasLoadedInitialThreadData = true - UIView.performWithoutAnimation { [weak self] in // Hide the 'loading conversations' label (now that we have received conversation data) self?.loadingConversationsLabel.isHidden = true @@ -422,6 +420,8 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData ) self?.viewModel.updateThreadData(updatedData) + self?.tableView.reloadData() + self?.hasLoadedInitialThreadData = true } return } @@ -460,7 +460,11 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData } private func autoLoadNextPageIfNeeded() { - guard !self.isAutoLoadingNextPage && !self.isLoadingMore else { return } + guard + self.hasLoadedInitialThreadData && + !self.isAutoLoadingNextPage && + !self.isLoadingMore + else { return } self.isAutoLoadingNextPage = true diff --git a/Session/Home/Message Requests/MessageRequestsViewController.swift b/Session/Home/Message Requests/MessageRequestsViewController.swift index b7c63b57d..42cb93344 100644 --- a/Session/Home/Message Requests/MessageRequestsViewController.swift +++ b/Session/Home/Message Requests/MessageRequestsViewController.swift @@ -232,9 +232,18 @@ class MessageRequestsViewController: BaseVC, SessionUtilRespondingViewController // 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 hasLoadedInitialThreadData else { - hasLoadedInitialThreadData = true 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 } return } @@ -271,7 +280,11 @@ class MessageRequestsViewController: BaseVC, SessionUtilRespondingViewController } private func autoLoadNextPageIfNeeded() { - guard !self.isAutoLoadingNextPage && !self.isLoadingMore else { return } + guard + self.hasLoadedInitialThreadData && + !self.isAutoLoadingNextPage && + !self.isLoadingMore + else { return } self.isAutoLoadingNextPage = true diff --git a/Session/Media Viewing & Editing/DocumentTitleViewController.swift b/Session/Media Viewing & Editing/DocumentTitleViewController.swift index f95682a55..d7a84d87e 100644 --- a/Session/Media Viewing & Editing/DocumentTitleViewController.swift +++ b/Session/Media Viewing & Editing/DocumentTitleViewController.swift @@ -153,7 +153,7 @@ public class DocumentTileViewController: UIViewController, UITableViewDelegate, } private func autoLoadNextPageIfNeeded() { - guard !self.isAutoLoadingNextPage else { return } + guard self.hasLoadedInitialData && !self.isAutoLoadingNextPage else { return } self.isAutoLoadingNextPage = true @@ -204,11 +204,11 @@ public class DocumentTileViewController: UIViewController, UITableViewDelegate, // 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 hasLoadedInitialData else { - self.hasLoadedInitialData = true self.viewModel.updateGalleryData(updatedGalleryData) UIView.performWithoutAnimation { self.tableView.reloadData() + self.hasLoadedInitialData = true self.performInitialScrollIfNeeded() } return diff --git a/Session/Media Viewing & Editing/MediaTileViewController.swift b/Session/Media Viewing & Editing/MediaTileViewController.swift index 649ed132a..5d24475b9 100644 --- a/Session/Media Viewing & Editing/MediaTileViewController.swift +++ b/Session/Media Viewing & Editing/MediaTileViewController.swift @@ -246,7 +246,7 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour } private func autoLoadNextPageIfNeeded() { - guard !self.isAutoLoadingNextPage else { return } + guard self.hasLoadedInitialData && !self.isAutoLoadingNextPage else { return } self.isAutoLoadingNextPage = true @@ -307,12 +307,12 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour // 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 hasLoadedInitialData else { - self.hasLoadedInitialData = true self.viewModel.updateGalleryData(updatedGalleryData) self.updateSelectButton(updatedData: updatedGalleryData, inBatchSelectMode: isInBatchSelectMode) UIView.performWithoutAnimation { self.collectionView.reloadData() + self.hasLoadedInitialData = true self.performInitialScrollIfNeeded() } return diff --git a/Session/Shared/SessionTableViewController.swift b/Session/Shared/SessionTableViewController.swift index ee330ce25..dc8c69a27 100644 --- a/Session/Shared/SessionTableViewController.swift +++ b/Session/Shared/SessionTableViewController.swift @@ -224,21 +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 { - hasLoadedInitialTableData = true 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 @@ -265,7 +272,11 @@ class SessionTableViewController