Fix crash when refreshing while logged in to a Pixelfed account
Closes #142
This commit is contained in:
parent
2798a199aa
commit
89a9bfba47
|
@ -85,9 +85,11 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
|||
case let .failure(error):
|
||||
completion(.failure(.client(error)))
|
||||
|
||||
case let .success(statuses, pagination):
|
||||
self.older = pagination?.older
|
||||
self.newer = pagination?.newer
|
||||
case let .success(statuses, _):
|
||||
if !statuses.isEmpty {
|
||||
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||
self.older = .before(id: statuses.last!.id, count: nil)
|
||||
}
|
||||
|
||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||
DispatchQueue.main.async {
|
||||
|
@ -139,15 +141,13 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
|||
case let .failure(error):
|
||||
completion(.failure(.client(error)))
|
||||
|
||||
case let .success(statuses, pagination):
|
||||
case let .success(statuses, _):
|
||||
guard !statuses.isEmpty else {
|
||||
completion(.failure(.noOlder))
|
||||
return
|
||||
}
|
||||
|
||||
if let older = pagination?.older {
|
||||
self.older = older
|
||||
}
|
||||
self.older = .before(id: statuses.last!.id, count: nil)
|
||||
|
||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||
var snapshot = currentSnapshot()
|
||||
|
@ -170,15 +170,13 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
|||
case let .failure(error):
|
||||
completion(.failure(.client(error)))
|
||||
|
||||
case let .success(statuses, pagination):
|
||||
case let .success(statuses, _):
|
||||
guard !statuses.isEmpty else {
|
||||
completion(.failure(.noNewer))
|
||||
completion(.failure(.allCaughtUp))
|
||||
return
|
||||
}
|
||||
|
||||
if let newer = pagination?.newer {
|
||||
self.newer = newer
|
||||
}
|
||||
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||
|
||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||
var snapshot = currentSnapshot()
|
||||
|
|
|
@ -151,9 +151,11 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
|||
case let .failure(error):
|
||||
completion(.failure(.client(error)))
|
||||
|
||||
case let .success(statuses, pagination):
|
||||
self.newer = pagination?.newer
|
||||
self.older = pagination?.older
|
||||
case let .success(statuses, _):
|
||||
if !statuses.isEmpty {
|
||||
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||
self.older = .before(id: statuses.last!.id, count: nil)
|
||||
}
|
||||
|
||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||
DispatchQueue.main.async {
|
||||
|
@ -194,8 +196,10 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
|||
case let .failure(error):
|
||||
completion(.failure(.client(error)))
|
||||
|
||||
case let .success(statuses, pagination):
|
||||
self.older = pagination?.older
|
||||
case let .success(statuses, _):
|
||||
if !statuses.isEmpty {
|
||||
self.older = .before(id: statuses.last!.id, count: nil)
|
||||
}
|
||||
|
||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||
var snapshot = currentSnapshot()
|
||||
|
@ -219,17 +223,13 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
|||
case let .failure(error):
|
||||
completion(.failure(.client(error)))
|
||||
|
||||
case let .success(statuses, pagination):
|
||||
case let .success(statuses, _):
|
||||
guard !statuses.isEmpty else {
|
||||
completion(.failure(.allCaughtUp))
|
||||
return
|
||||
}
|
||||
|
||||
// if there are no new statuses, pagination is nil
|
||||
// if we were to then overwrite self.newer, future refresh would fail
|
||||
if let newer = pagination?.newer {
|
||||
self.newer = newer
|
||||
}
|
||||
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||
|
||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||
var snapshot = currentSnapshot()
|
||||
|
|
Loading…
Reference in New Issue