Fix race condition loading bookmarks
This commit is contained in:
parent
f2a8b91769
commit
c7b4d00da7
|
@ -45,13 +45,14 @@ class BookmarksTableViewController: EnhancedTableViewController {
|
||||||
let request = Client.getBookmarks()
|
let request = Client.getBookmarks()
|
||||||
mastodonController.run(request) { (response) in
|
mastodonController.run(request) { (response) in
|
||||||
guard case let .success(statuses, pagination) = response else { fatalError() }
|
guard case let .success(statuses, pagination) = response else { fatalError() }
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses)
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
self.statuses.append(contentsOf: statuses.map { ($0.id, .unknown) })
|
self.statuses.append(contentsOf: statuses.map { ($0.id, .unknown) })
|
||||||
self.newer = pagination?.newer
|
self.newer = pagination?.newer
|
||||||
self.older = pagination?.older
|
self.older = pagination?.older
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.tableView.reloadData()
|
self.tableView.reloadData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,15 +88,16 @@ class BookmarksTableViewController: 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)
|
self.mastodonController.persistentContainer.addAll(statuses: newStatuses) {
|
||||||
let newIndexPaths = (self.statuses.count..<(self.statuses.count + newStatuses.count)).map {
|
let newIndexPaths = (self.statuses.count..<(self.statuses.count + newStatuses.count)).map {
|
||||||
IndexPath(row: $0, section: 0)
|
IndexPath(row: $0, section: 0)
|
||||||
}
|
}
|
||||||
self.statuses.append(contentsOf: newStatuses.map { ($0.id, .unknown) })
|
self.statuses.append(contentsOf: newStatuses.map { ($0.id, .unknown) })
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
UIView.performWithoutAnimation {
|
UIView.performWithoutAnimation {
|
||||||
self.tableView.insertRows(at: newIndexPaths, with: .automatic)
|
self.tableView.insertRows(at: newIndexPaths, with: .automatic)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue