forked from shadowfacts/Tusker
Prevent potential race condition when loading additional statuses
This commit is contained in:
parent
273b74ddfb
commit
9b04b75949
|
@ -179,11 +179,12 @@ class TimelineTableViewController: EnhancedTableViewController {
|
||||||
mastodonController.run(request) { response in
|
mastodonController.run(request) { response in
|
||||||
guard case let .success(newStatuses, pagination) = response else { fatalError() }
|
guard case let .success(newStatuses, pagination) = response else { fatalError() }
|
||||||
self.older = pagination?.older
|
self.older = pagination?.older
|
||||||
|
self.mastodonController.persistentContainer.addAll(statuses: newStatuses) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
let newRows = self.timelineSegments.last!.count..<(self.timelineSegments.last!.count + newStatuses.count)
|
let newRows = self.timelineSegments.last!.count..<(self.timelineSegments.last!.count + newStatuses.count)
|
||||||
let newIndexPaths = newRows.map { IndexPath(row: $0, section: self.timelineSegments.count - 1) }
|
let newIndexPaths = newRows.map { IndexPath(row: $0, section: self.timelineSegments.count - 1) }
|
||||||
self.timelineSegments[self.timelineSegments.count - 1].append(contentsOf: newStatuses.map { ($0.id, .unknown) })
|
self.timelineSegments[self.timelineSegments.count - 1].append(contentsOf: newStatuses.map { ($0.id, .unknown) })
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: newStatuses) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
UIView.performWithoutAnimation {
|
UIView.performWithoutAnimation {
|
||||||
self.tableView.insertRows(at: newIndexPaths, with: .none)
|
self.tableView.insertRows(at: newIndexPaths, with: .none)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue