From 124997feca9b58b63b79a955638b2bfb2f242636 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 22 Sep 2019 21:20:01 -0500 Subject: [PATCH] Reset feed to feed metadata relationship on reload --- Frameworks/Account/Account.swift | 7 +++++++ Frameworks/Account/AccountMetadataFile.swift | 2 +- Frameworks/Account/Feed.swift | 3 ++- Frameworks/Account/FeedMetadataFile.swift | 3 ++- iOS/MasterFeed/MasterFeedViewController.swift | 5 +++++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index e18569f2b..09eacbf82 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -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
, statusKey: ArticleStatus.Key, flag: Bool) -> Set
? { return delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag) } diff --git a/Frameworks/Account/AccountMetadataFile.swift b/Frameworks/Account/AccountMetadataFile.swift index e27455c07..14457dc45 100644 --- a/Frameworks/Account/AccountMetadataFile.swift +++ b/Frameworks/Account/AccountMetadataFile.swift @@ -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() { diff --git a/Frameworks/Account/Feed.swift b/Frameworks/Account/Feed.swift index f7c994409..5a7a4c3ec 100644 --- a/Frameworks/Account/Feed.swift +++ b/Frameworks/Account/Feed.swift @@ -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 diff --git a/Frameworks/Account/FeedMetadataFile.swift b/Frameworks/Account/FeedMetadataFile.swift index 739518232..e9314a4f0 100644 --- a/Frameworks/Account/FeedMetadataFile.swift +++ b/Frameworks/Account/FeedMetadataFile.swift @@ -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 } } diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 61a9ce8d0..10006583b 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -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