Simplify the article replacement logic

This commit is contained in:
Maurice Parker 2019-09-03 16:07:02 -05:00
parent 5cb099aee6
commit 640faaa114
2 changed files with 9 additions and 20 deletions

View File

@ -132,10 +132,6 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
resetUI() resetUI()
} }
func updateArticles() {
reloadAllVisibleCells()
}
func reloadArticles(animate: Bool) { func reloadArticles(animate: Bool) {
applyChanges(animate: animate) { [weak self] in applyChanges(animate: animate) { [weak self] in
self?.updateArticleSelection(animate: animate) self?.updateArticleSelection(animate: animate)

View File

@ -176,22 +176,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
private(set) var currentArticleIndexPath: IndexPath? private(set) var currentArticleIndexPath: IndexPath?
private(set) var articles = ArticleArray() { private(set) var articles = ArticleArray()
didSet {
if articles == oldValue {
return
}
if articles.representSameArticlesInSameOrder(as: oldValue) {
articleRowMap = [String: Int]()
masterTimelineViewController?.updateArticles()
updateUnreadCount()
return
}
updateShowAvatars()
articleRowMap = [String: Int]()
updateUnreadCount()
}
}
var isTimelineUnreadAvailable: Bool { var isTimelineUnreadAvailable: Bool {
if let unreadProvider = timelineFetcher as? UnreadCountProvider { if let unreadProvider = timelineFetcher as? UnreadCountProvider {
@ -1000,13 +985,21 @@ private extension SceneCoordinator {
func replaceArticles(with unsortedArticles: Set<Article>, animate: Bool) { func replaceArticles(with unsortedArticles: Set<Article>, animate: Bool) {
let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection) let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection)
if articles != sortedArticles { if articles != sortedArticles {
let article = currentArticle let article = currentArticle
articles = sortedArticles articles = sortedArticles
updateShowAvatars()
articleRowMap = [String: Int]()
updateUnreadCount()
masterTimelineViewController?.reloadArticles(animate: animate) masterTimelineViewController?.reloadArticles(animate: animate)
if let articleID = article?.articleID, let index = indexForArticleID(articleID) { if let articleID = article?.articleID, let index = indexForArticleID(articleID) {
currentArticleIndexPath = IndexPath(row: index, section: 0) currentArticleIndexPath = IndexPath(row: index, section: 0)
} }
} }
} }