Make updating the timeline cells more efficient after downloading an avatar.

This commit is contained in:
Brent Simmons 2018-01-06 11:18:03 -08:00
parent b83e0eeb67
commit f9b4e192e0
1 changed files with 12 additions and 8 deletions

View File

@ -327,19 +327,20 @@ class TimelineViewController: NSViewController, UndoableCommandRunner {
@objc func avatarDidBecomeAvailable(_ note: Notification) {
guard let avatarURL = note.userInfo?[UserInfoKey.url] as? String else {
guard showAvatars, let avatarURL = note.userInfo?[UserInfoKey.url] as? String else {
return
}
let articlesToReload = articles.filter { (article) -> Bool in
guard let authors = article.authors else {
return false
var articlesToReload = [Article]()
tableView.enumerateAvailableRowViews { (rowView, row) in
guard let article = articles.articleAtRow(row), let authors = article.authors, !authors.isEmpty else {
return
}
for oneAuthor in authors {
if oneAuthor.avatarURL == avatarURL {
return true
for author in authors {
if author.avatarURL == avatarURL {
articlesToReload.append(article)
}
}
return false
}
reloadCellsForArticles(articlesToReload)
}
@ -373,6 +374,9 @@ class TimelineViewController: NSViewController, UndoableCommandRunner {
private func reloadCellsForArticleIDs(_ articleIDs: Set<String>) {
if articleIDs.isEmpty {
return
}
let indexes = articles.indexesForArticleIDs(articleIDs)
tableView.reloadData(forRowIndexes: indexes, columnIndexes: NSIndexSet(index: 0) as IndexSet)
}