mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-11 17:24:04 +01:00
Update the timeline with status changes
This commit is contained in:
parent
2d57945e98
commit
bf8a52d710
@ -19,19 +19,16 @@ struct TimelineItem: Identifiable {
|
|||||||
|
|
||||||
var article: Article
|
var article: Article
|
||||||
|
|
||||||
|
init(article: Article) {
|
||||||
|
self.article = article
|
||||||
|
updateStatus()
|
||||||
|
}
|
||||||
|
|
||||||
var id: String {
|
var id: String {
|
||||||
return article.articleID
|
return article.articleID
|
||||||
}
|
}
|
||||||
|
|
||||||
var status: TimelineItemStatus {
|
var status: TimelineItemStatus = .showNone
|
||||||
if article.status.starred == true {
|
|
||||||
return .showStar
|
|
||||||
}
|
|
||||||
if article.status.read == false {
|
|
||||||
return .showUnread
|
|
||||||
}
|
|
||||||
return .showNone
|
|
||||||
}
|
|
||||||
|
|
||||||
var byline: String {
|
var byline: String {
|
||||||
return article.webFeed?.nameForDisplay ?? ""
|
return article.webFeed?.nameForDisplay ?? ""
|
||||||
@ -41,4 +38,16 @@ struct TimelineItem: Identifiable {
|
|||||||
return ArticleStringFormatter.dateString(article.logicalDatePublished)
|
return ArticleStringFormatter.dateString(article.logicalDatePublished)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutating func updateStatus() {
|
||||||
|
if article.status.starred == true {
|
||||||
|
status = .showStar
|
||||||
|
} else {
|
||||||
|
if article.status.read == false {
|
||||||
|
status = .showUnread
|
||||||
|
} else {
|
||||||
|
status = .showNone
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class TimelineModel: ObservableObject {
|
|||||||
|
|
||||||
private var articleDictionaryNeedsUpdate = true
|
private var articleDictionaryNeedsUpdate = true
|
||||||
private var _idToArticleDictionary = [String: Article]()
|
private var _idToArticleDictionary = [String: Article]()
|
||||||
private var idToAticleDictionary: [String: Article] {
|
private var idToArticleDictionary: [String: Article] {
|
||||||
if articleDictionaryNeedsUpdate {
|
if articleDictionaryNeedsUpdate {
|
||||||
rebuildArticleDictionaries()
|
rebuildArticleDictionaries()
|
||||||
}
|
}
|
||||||
@ -59,6 +59,7 @@ class TimelineModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: API
|
// MARK: API
|
||||||
@ -77,7 +78,7 @@ class TimelineModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func articleFor(_ articleID: String) -> Article? {
|
func articleFor(_ articleID: String) -> Article? {
|
||||||
return idToAticleDictionary[articleID]
|
return idToArticleDictionary[articleID]
|
||||||
}
|
}
|
||||||
|
|
||||||
func findPrevArticle(_ article: Article) -> Article? {
|
func findPrevArticle(_ article: Article) -> Article? {
|
||||||
@ -104,6 +105,21 @@ class TimelineModel: ObservableObject {
|
|||||||
|
|
||||||
private extension TimelineModel {
|
private extension TimelineModel {
|
||||||
|
|
||||||
|
// MARK: Notifications
|
||||||
|
|
||||||
|
@objc func statusesDidChange(_ note: Notification) {
|
||||||
|
guard let articleIDs = note.userInfo?[Account.UserInfoKey.articleIDs] as? Set<String> else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i in 0..<timelineItems.count {
|
||||||
|
if articleIDs.contains(timelineItems[i].article.articleID) {
|
||||||
|
timelineItems[i].updateStatus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK:
|
||||||
|
|
||||||
func sortParametersDidChange() {
|
func sortParametersDidChange() {
|
||||||
performBlockAndRestoreSelection {
|
performBlockAndRestoreSelection {
|
||||||
let unsortedArticles = Set(articles)
|
let unsortedArticles = Set(articles)
|
||||||
|
Loading…
Reference in New Issue
Block a user