Fixed a somehow reproducable crash

Fixed a crash when autoLoadNextPageIfNeeded was run after the table data was updated but before the tableView was reloaded resulting in a index out of bounds exception
pull/751/head
Morgan Pretty 2 years ago
parent 7b70f8d535
commit f45568644e

@ -875,7 +875,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
@ -883,6 +882,7 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
UIView.performWithoutAnimation {
self.tableView.reloadData()
self.hasLoadedInitialInteractionData = true
self.performInitialScrollIfNeeded()
}
}
@ -1191,7 +1191,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

@ -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

@ -232,9 +232,10 @@ 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)
tableView.reloadData()
hasLoadedInitialThreadData = true
}
return
}
@ -271,7 +272,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

@ -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

@ -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

@ -227,9 +227,10 @@ class SessionTableViewController<NavItemId: Equatable, Section: SessionTableSect
// 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)
tableView.reloadData()
hasLoadedInitialTableData = true
}
return
}
@ -265,7 +266,11 @@ class SessionTableViewController<NavItemId: Equatable, Section: SessionTableSect
}
private func autoLoadNextPageIfNeeded() {
guard !self.isAutoLoadingNextPage && !self.isLoadingMore else { return }
guard
self.hasLoadedInitialTableData &&
!self.isAutoLoadingNextPage &&
!self.isLoadingMore
else { return }
self.isAutoLoadingNextPage = true

@ -5,6 +5,9 @@ import GRDB
import Quick
import Nimble
import SessionUIKit
import SessionSnodeKit
@testable import Session
class NotificationContentViewModelSpec: QuickSpec {

Loading…
Cancel
Save