forked from shadowfacts/Tusker
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):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
self.older = pagination?.older
|
if !statuses.isEmpty {
|
||||||
self.newer = pagination?.newer
|
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||||
|
self.older = .before(id: statuses.last!.id, count: nil)
|
||||||
|
}
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
@ -139,15 +141,13 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
guard !statuses.isEmpty else {
|
guard !statuses.isEmpty else {
|
||||||
completion(.failure(.noOlder))
|
completion(.failure(.noOlder))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let older = pagination?.older {
|
self.older = .before(id: statuses.last!.id, count: nil)
|
||||||
self.older = older
|
|
||||||
}
|
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
var snapshot = currentSnapshot()
|
var snapshot = currentSnapshot()
|
||||||
|
@ -170,15 +170,13 @@ class ProfileStatusesViewController: DiffableTimelineLikeTableViewController<Pro
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
guard !statuses.isEmpty else {
|
guard !statuses.isEmpty else {
|
||||||
completion(.failure(.noNewer))
|
completion(.failure(.allCaughtUp))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let newer = pagination?.newer {
|
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||||
self.newer = newer
|
|
||||||
}
|
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
var snapshot = currentSnapshot()
|
var snapshot = currentSnapshot()
|
||||||
|
|
|
@ -151,9 +151,11 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
self.newer = pagination?.newer
|
if !statuses.isEmpty {
|
||||||
self.older = pagination?.older
|
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||||
|
self.older = .before(id: statuses.last!.id, count: nil)
|
||||||
|
}
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
@ -194,8 +196,10 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
self.older = pagination?.older
|
if !statuses.isEmpty {
|
||||||
|
self.older = .before(id: statuses.last!.id, count: nil)
|
||||||
|
}
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
var snapshot = currentSnapshot()
|
var snapshot = currentSnapshot()
|
||||||
|
@ -219,17 +223,13 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
|
||||||
case let .failure(error):
|
case let .failure(error):
|
||||||
completion(.failure(.client(error)))
|
completion(.failure(.client(error)))
|
||||||
|
|
||||||
case let .success(statuses, pagination):
|
case let .success(statuses, _):
|
||||||
guard !statuses.isEmpty else {
|
guard !statuses.isEmpty else {
|
||||||
completion(.failure(.allCaughtUp))
|
completion(.failure(.allCaughtUp))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are no new statuses, pagination is nil
|
self.newer = .after(id: statuses.first!.id, count: nil)
|
||||||
// if we were to then overwrite self.newer, future refresh would fail
|
|
||||||
if let newer = pagination?.newer {
|
|
||||||
self.newer = newer
|
|
||||||
}
|
|
||||||
|
|
||||||
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
|
||||||
var snapshot = currentSnapshot()
|
var snapshot = currentSnapshot()
|
||||||
|
|
Loading…
Reference in New Issue