Skip to content

Commit

Permalink
bring back the top read previous date lookup
Browse files Browse the repository at this point in the history
for situations when today’s content isn’t ready yet
  • Loading branch information
joewalsh committed Jan 5, 2017
1 parent 62fa55e commit c575ac7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions TopReadWidget/WMFTodayTopReadWidgetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit c575ac7

Please sign in to comment.