Add new articles to the timeline when a feed that affects the timeline gets new articles. Fix #166.

This commit is contained in:
Brent Simmons 2018-01-20 16:54:18 -08:00
parent 982b2d2d3f
commit 807ad99aad

View File

@ -642,7 +642,12 @@ private extension TimelineViewController {
} }
let fetchedArticles = fetchUnsortedArticles(for: representedObjects) let fetchedArticles = fetchUnsortedArticles(for: representedObjects)
let sortedArticles = Array(fetchedArticles).sortedByDate() updateArticles(with: fetchedArticles)
}
func updateArticles(with unsortedArticles: Set<Article>) {
let sortedArticles = Array(unsortedArticles).sortedByDate()
if articles != sortedArticles { if articles != sortedArticles {
articles = sortedArticles articles = sortedArticles
} }
@ -667,20 +672,27 @@ private extension TimelineViewController {
func fetchAndMergeArticles() { func fetchAndMergeArticles() {
guard let representedObjects = representedObjects else {
return
}
let selectedArticleIDs = selectedArticles.articleIDs() let selectedArticleIDs = selectedArticles.articleIDs()
var unsortedArticles = fetchUnsortedArticles(for: representedObjects)
unsortedArticles.formUnion(Set(articles))
updateArticles(with: unsortedArticles)
selectArticles(selectedArticleIDs) selectArticles(selectedArticleIDs)
} }
func selectArticles(_ articleIDs: [String]) { func selectArticles(_ articleIDs: [String]) {
// let indexesToSelect = indexesOf(articleIDs) let indexesToSelect = articles.indexesForArticleIDs(Set(articleIDs))
// if indexesToSelect.isEmpty { if indexesToSelect.isEmpty {
// tableView.deselectAll(self) tableView.deselectAll(self)
// return return
// } }
// tableView.selectRowIndexes(indexesToSelect, byExtendingSelection: false) tableView.selectRowIndexes(indexesToSelect, byExtendingSelection: false)
} }
func invalidateFetchAndMergeArticlesTimer() { func invalidateFetchAndMergeArticlesTimer() {