Reset feed to feed metadata relationship on reload

This commit is contained in:
Maurice Parker 2019-09-22 21:20:01 -05:00
parent c9dc987f64
commit 124997feca
5 changed files with 17 additions and 3 deletions

View File

@ -29,6 +29,7 @@ public extension Notification.Name {
static let AccountDidDownloadArticles = Notification.Name(rawValue: "AccountDidDownloadArticles")
static let AccountStateDidChange = Notification.Name(rawValue: "AccountStateDidChange")
static let StatusesDidChange = Notification.Name(rawValue: "StatusesDidChange")
static let FeedMetadataDidChange = Notification.Name(rawValue: "FeedMetadataDidChange")
}
public enum AccountType: Int {
@ -401,6 +402,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
public func resetAllFeedMetadata() {
for feed in flattenedFeeds() {
feed.metadata = feedMetadata(feedURL: feed.url, feedID: feed.feedID)
}
}
public func markArticles(_ articles: Set<Article>, statusKey: ArticleStatus.Key, flag: Bool) -> Set<Article>? {
return delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag)
}

View File

@ -48,6 +48,7 @@ private extension AccountMetadataFile {
if let fileData = try? Data(contentsOf: readURL) {
let decoder = PropertyListDecoder()
account.metadata = (try? decoder.decode(AccountMetadata.self, from: fileData)) ?? AccountMetadata()
account.metadata.delegate = account
}
})
@ -55,7 +56,6 @@ private extension AccountMetadataFile {
os_log(.error, log: log, "Read from disk coordination failed: %@.", error.localizedDescription)
}
account.metadata.delegate = account
}
func saveCallback() {

View File

@ -196,10 +196,11 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
}
}
var metadata: FeedMetadata
// MARK: - Private
private let accountID: String // Used for hashing and equality; account may turn nil
private let metadata: FeedMetadata
// MARK: - Init

View File

@ -48,6 +48,8 @@ private extension FeedMetadataFile {
if let fileData = try? Data(contentsOf: readURL) {
let decoder = PropertyListDecoder()
account.feedMetadata = (try? decoder.decode(Account.FeedMetadataDictionary.self, from: fileData)) ?? Account.FeedMetadataDictionary()
account.feedMetadata.values.forEach { $0.delegate = account }
account.resetAllFeedMetadata()
}
})
@ -55,7 +57,6 @@ private extension FeedMetadataFile {
os_log(.error, log: log, "Read from disk coordination failed: %@.", error.localizedDescription)
}
account.feedMetadata.values.forEach { $0.delegate = account }
}

View File

@ -53,6 +53,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(feedMetadataDidChange(_:)), name: .FeedMetadataDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
@ -123,6 +124,10 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
}
}
@objc func feedMetadataDidChange(_ note: Notification) {
reloadAllVisibleCells()
}
@objc func userDidAddFeed(_ notification: Notification) {
guard let feed = notification.userInfo?[UserInfoKey.feed] as? Feed else {
return