From c575ac77bce07667f18bb5274dcf26a7b7ab243b Mon Sep 17 00:00:00 2001 From: joewalsh Date: Thu, 5 Jan 2017 13:57:36 -0500 Subject: [PATCH] bring back the top read previous date lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit for situations when today’s content isn’t ready yet --- .../WMFTodayTopReadWidgetViewController.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/TopReadWidget/WMFTodayTopReadWidgetViewController.swift b/TopReadWidget/WMFTodayTopReadWidgetViewController.swift index 2c32efde387..25625c89980 100644 --- a/TopReadWidget/WMFTodayTopReadWidgetViewController.swift +++ b/TopReadWidget/WMFTodayTopReadWidgetViewController.swift @@ -370,15 +370,23 @@ class WMFTodayTopReadWidgetViewController: UIViewController, NCWidgetProviding { return } - guard attempt < 3 else { + guard attempt < 4 else { completionHandler(.noData) return } contentSource.loadContent(for: date, force: false) { DispatchQueue.main.async(execute: { guard self.updateUIWithTopReadFromContentStoreForSiteURL(siteURL: siteURL, date: date) else { - let todayUTC = (date as NSDate).wmf_midnightLocalDateForEquivalentUTC as Date - self.fetch(siteURL: siteURL, date: todayUTC, attempt: attempt + 1, completionHandler: completionHandler) + if (attempt == 1) { + let todayUTC = (date as NSDate).wmf_midnightLocalDateForEquivalentUTC as Date + self.fetch(siteURL: siteURL, date: todayUTC, attempt: attempt + 1, completionHandler: completionHandler) + } else { + guard let previousDate = NSCalendar.wmf_gregorian().date(byAdding: .day, value: -1, to: date, options: .matchStrictly) else { + completionHandler(.noData) + return + } + self.fetch(siteURL: siteURL, date: previousDate, attempt: attempt + 1, completionHandler: completionHandler) + } return }