From edd89450aa8a8e861544a53a27d94b8a9af22c3a Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 4 Apr 2021 14:43:51 -0400 Subject: [PATCH] Fail gracefully when fetching statuses in timeline controller --- .../Timeline/TimelineTableViewController.swift | 15 ++++++++++++--- .../TimelineLikeTableViewController.swift | 11 ++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineTableViewController.swift b/Tusker/Screens/Timeline/TimelineTableViewController.swift index a28fd626..b2905246 100644 --- a/Tusker/Screens/Timeline/TimelineTableViewController.swift +++ b/Tusker/Screens/Timeline/TimelineTableViewController.swift @@ -72,7 +72,10 @@ class TimelineTableViewController: TimelineLikeTableViewController: EnhancedTableViewController, Refres func loadInitial() { guard !loaded else { return } + // set loaded immediately so we don't trigger another request while the current one is running loaded = true loadInitialItems() { (items) in - guard items.count > 0 else { return } DispatchQueue.main.async { + guard items.count > 0 else { + // set loaded back to false so the next time the VC appears, we try to load again + // todo: this should probably retry automatically + self.loaded = false + return + } + if self.sections.count < self.headerSectionsCount() { self.sections.insert(contentsOf: Array(repeating: [], count: self.headerSectionsCount() - self.sections.count), at: 0) } @@ -97,6 +104,8 @@ class TimelineLikeTableViewController: EnhancedTableViewController, Refres return "Refresh" } + // todo: these three should use Result<[Item], Client.Error> so we can differentiate between failed requests and there actually being no results + func loadInitialItems(completion: @escaping ([Item]) -> Void) { fatalError("loadInitialItems(completion:) must be implemented by subclasses") }