From db4312ee34fea7fa8f5492617cf12f56695ed692 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 7 Jan 2020 21:54:19 -0500 Subject: [PATCH] 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 --- .../Notifications/NotificationsTableViewController.swift | 6 ++++-- Tusker/Screens/Profile/ProfileTableViewController.swift | 4 +++- Tusker/Screens/Timeline/TimelineTableViewController.swift | 7 ++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Tusker/Screens/Notifications/NotificationsTableViewController.swift b/Tusker/Screens/Notifications/NotificationsTableViewController.swift index c68ac440c1..0bd72ca57c 100644 --- a/Tusker/Screens/Notifications/NotificationsTableViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsTableViewController.swift @@ -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() diff --git a/Tusker/Screens/Profile/ProfileTableViewController.swift b/Tusker/Screens/Profile/ProfileTableViewController.swift index ecf12bfd71..f969d7817a 100644 --- a/Tusker/Screens/Profile/ProfileTableViewController.swift +++ b/Tusker/Screens/Profile/ProfileTableViewController.swift @@ -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() diff --git a/Tusker/Screens/Timeline/TimelineTableViewController.swift b/Tusker/Screens/Timeline/TimelineTableViewController.swift index c5096da3f2..f7321f38df 100644 --- a/Tusker/Screens/Timeline/TimelineTableViewController.swift +++ b/Tusker/Screens/Timeline/TimelineTableViewController.swift @@ -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()