From c0097ba75290b61b5d35978ef0a2333bf97d9f93 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 15 Aug 2021 18:44:23 -0400 Subject: [PATCH] Fix potential race condition with DiffableTimelineLikeTableViewController --- .../TimelineTableViewController.swift | 14 ++++---- ...fableTimelineLikeTableViewController.swift | 32 +++++++++++-------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineTableViewController.swift b/Tusker/Screens/Timeline/TimelineTableViewController.swift index 254bd8459d..b5423d0b7c 100644 --- a/Tusker/Screens/Timeline/TimelineTableViewController.swift +++ b/Tusker/Screens/Timeline/TimelineTableViewController.swift @@ -168,7 +168,7 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController Void) { + override func loadOlderItems(currentSnapshot: @escaping () -> Snapshot, completion: @escaping (LoadResult) -> Void) { guard let older = older else { completion(.failure(.noOlder)) return @@ -176,12 +176,12 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController Void) { + override func loadNewerItems(currentSnapshot: @escaping () -> Snapshot, completion: @escaping (LoadResult) -> Void) { guard let newer = newer else { completion(.failure(.noNewer)) return @@ -228,7 +228,7 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController Snapshot = { + let snapshot = self.dataSource.snapshot() + + for section in self.timelineContentSections() { + if snapshot.indexOfSection(section) != nil, + let first = snapshot.itemIdentifiers(inSection: section).first { + firstItem = first + break + } } + + return snapshot } - loadNewerItems(currentSnapshot: snapshot) { result in + loadNewerItems(currentSnapshot: currentSnapshot) { result in DispatchQueue.main.async { self.refreshControl?.endRefreshing() self.state = .loaded @@ -231,8 +235,8 @@ class DiffableTimelineLikeTableViewController Void) { + func loadOlderItems(currentSnapshot: @escaping () -> Snapshot, completion: @escaping (LoadResult) -> Void) { fatalError("loadOlderItesm(completion:) must be implemented by subclasses") } - func loadNewerItems(currentSnapshot: Snapshot, completion: @escaping (LoadResult) -> Void) { + func loadNewerItems(currentSnapshot: @escaping () -> Snapshot, completion: @escaping (LoadResult) -> Void) { fatalError("loadNewerItems(completion:) must be implemented by subclasses") }