Fix refreshing multiple times with no new data not working

When the requested range has no results, no pagination data is returned,
so the existing `newer` request range is replaced with nil. As there
was no new data, the existing request range is still correct and should
not be replaced.

Fixes #75
This commit is contained in:
Shadowfacts 2020-01-07 21:54:19 -05:00
parent ec2062ad42
commit db4312ee34
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 13 additions and 4 deletions

View File

@ -208,8 +208,10 @@ class NotificationsTableViewController: EnhancedTableViewController {
MastodonCache.addAll(statuses: newNotifications.compactMap { $0.status })
MastodonCache.addAll(accounts: newNotifications.map { $0.account })
self.newer = pagination?.newer
if let newer = pagination?.newer {
self.newer = newer
}
DispatchQueue.main.async {
self.refreshControl?.endRefreshing()

View File

@ -218,7 +218,9 @@ class ProfileTableViewController: EnhancedTableViewController {
MastodonCache.addAll(statuses: newStatuses)
self.timelineSegments[0].insert(contentsOf: newStatuses.map { ($0.id, .unknown) }, at: 0)
self.newer = pagination?.newer
if let newer = pagination?.newer {
self.newer = newer
}
DispatchQueue.main.async {
self.refreshControl?.endRefreshing()

View File

@ -127,9 +127,14 @@ class TimelineTableViewController: EnhancedTableViewController {
let request = MastodonController.client.getStatuses(timeline: timeline, range: newer)
MastodonController.client.run(request) { response in
guard case let .success(newStatuses, pagination) = response else { fatalError() }
self.newer = pagination?.newer
MastodonCache.addAll(statuses: newStatuses)
self.timelineSegments[0].insert(contentsOf: newStatuses.map { ($0.id, .unknown) }, at: 0)
if let newer = pagination?.newer {
self.newer = newer
}
DispatchQueue.main.async {
self.refreshControl?.endRefreshing()