Rename WebFeedMetadata to FeedMetadata.

This commit is contained in:
Brent Simmons
2023-07-02 16:12:43 -07:00
parent c84f2a80bd
commit e3cddc2bc2
13 changed files with 65 additions and 65 deletions

View File

@@ -221,9 +221,9 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
}
private lazy var webFeedMetadataFile = WebFeedMetadataFile(filename: (dataFolder as NSString).appendingPathComponent("FeedMetadata.plist"), account: self)
typealias WebFeedMetadataDictionary = [String: WebFeedMetadata]
var webFeedMetadata = WebFeedMetadataDictionary()
private lazy var feedMetadataFile = FeedMetadataFile(filename: (dataFolder as NSString).appendingPathComponent("FeedMetadata.plist"), account: self)
typealias FeedMetadataDictionary = [String: FeedMetadata]
var feedMetadata = FeedMetadataDictionary()
public var unreadCount = 0 {
didSet {
@@ -315,7 +315,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
NotificationCenter.default.addObserver(self, selector: #selector(childrenDidChange(_:)), name: .ChildrenDidChange, object: nil)
metadataFile.load()
webFeedMetadataFile.load()
feedMetadataFile.load()
opmlFile.load()
var shouldHandleRetentionPolicyChange = false
@@ -485,7 +485,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
public func save() {
metadataFile.save()
webFeedMetadataFile.save()
feedMetadataFile.save()
opmlFile.save()
}
@@ -577,7 +577,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
func newWebFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> WebFeed {
let feedURL = opmlFeedSpecifier.feedURL
let metadata = webFeedMetadata(feedURL: feedURL, webFeedID: feedURL)
let metadata = feedMetadata(feedURL: feedURL, webFeedID: feedURL)
let feed = WebFeed(account: self, url: opmlFeedSpecifier.feedURL, metadata: metadata)
if let feedTitle = opmlFeedSpecifier.title {
if feed.name == nil {
@@ -596,7 +596,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
func createWebFeed(with name: String?, url: String, webFeedID: String, homePageURL: String?) -> WebFeed {
let metadata = webFeedMetadata(feedURL: url, webFeedID: webFeedID)
let metadata = feedMetadata(feedURL: url, webFeedID: webFeedID)
let feed = WebFeed(account: self, url: url, metadata: metadata)
feed.name = name
feed.homePageURL = homePageURL
@@ -639,8 +639,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
delegate.markArticles(for: self, articles: articles, statusKey: statusKey, flag: flag, completion: completion)
}
func clearWebFeedMetadata(_ feed: WebFeed) {
webFeedMetadata[feed.url] = nil
func clearFeedMetadata(_ feed: WebFeed) {
feedMetadata[feed.url] = nil
}
func addFolder(_ folder: Folder) {
@@ -1030,11 +1030,11 @@ extension Account: AccountMetadataDelegate {
// MARK: - FeedMetadataDelegate
extension Account: WebFeedMetadataDelegate {
extension Account: FeedMetadataDelegate {
func valueDidChange(_ feedMetadata: WebFeedMetadata, key: WebFeedMetadata.CodingKeys) {
webFeedMetadataFile.markAsDirty()
guard let feed = existingWebFeed(withWebFeedID: feedMetadata.webFeedID) else {
func valueDidChange(_ feedMetadata: FeedMetadata, key: FeedMetadata.CodingKeys) {
feedMetadataFile.markAsDirty()
guard let feed = existingWebFeed(withWebFeedID: feedMetadata.feedID) else {
return
}
feed.postFeedSettingDidChangeNotification(key)
@@ -1231,14 +1231,14 @@ private extension Account {
private extension Account {
func webFeedMetadata(feedURL: String, webFeedID: String) -> WebFeedMetadata {
if let d = webFeedMetadata[feedURL] {
func feedMetadata(feedURL: String, webFeedID: String) -> FeedMetadata {
if let d = feedMetadata[feedURL] {
assert(d.delegate === self)
return d
}
let d = WebFeedMetadata(webFeedID: webFeedID)
let d = FeedMetadata(webFeedID: webFeedID)
d.delegate = self
webFeedMetadata[feedURL] = d
feedMetadata[feedURL] = d
return d
}

View File

@@ -204,14 +204,14 @@ final class CloudKitAccountDelegate: AccountDelegate, Logging {
removeWebFeedFromCloud(for: account, with: feed, from: container) { result in
switch result {
case .success:
account.clearWebFeedMetadata(feed)
account.clearFeedMetadata(feed)
container.removeWebFeed(feed)
completion(.success(()))
case .failure(let error):
switch error {
case CloudKitZoneError.corruptAccount:
// We got into a bad state and should remove the feed to clear up the bad data
account.clearWebFeedMetadata(feed)
account.clearFeedMetadata(feed)
container.removeWebFeed(feed)
default:
completion(.failure(error))

View File

@@ -11,14 +11,14 @@ import Articles
import RSParser
public extension Notification.Name {
static let WebFeedSettingDidChange = Notification.Name(rawValue: "FeedSettingDidChangeNotification")
static let FeedSettingDidChange = Notification.Name(rawValue: "FeedSettingDidChangeNotification")
}
public extension WebFeed {
static let WebFeedSettingUserInfoKey = "feedSetting"
static let FeedSettingUserInfoKey = "feedSetting"
struct WebFeedSettingKey {
struct FeedSettingKey {
public static let homePageURL = "homePageURL"
public static let iconURL = "iconURL"
public static let faviconURL = "faviconURL"
@@ -40,9 +40,9 @@ extension WebFeed {
authors = Author.authorsWithParsedAuthors(parsedFeed.authors)
}
func postFeedSettingDidChangeNotification(_ codingKey: WebFeedMetadata.CodingKeys) {
let userInfo = [WebFeed.WebFeedSettingUserInfoKey: codingKey.stringValue]
NotificationCenter.default.post(name: .WebFeedSettingDidChange, object: self, userInfo: userInfo)
func postFeedSettingDidChangeNotification(_ codingKey: FeedMetadata.CodingKeys) {
let userInfo = [WebFeed.FeedSettingUserInfoKey: codingKey.stringValue]
NotificationCenter.default.post(name: .FeedSettingDidChange, object: self, userInfo: userInfo)
}
}

View File

@@ -1,5 +1,5 @@
//
// WebFeedMetadata.swift
// FeedMetadata.swift
// NetNewsWire
//
// Created by Brent Simmons on 3/12/19.
@@ -10,14 +10,14 @@ import Foundation
import RSWeb
import Articles
protocol WebFeedMetadataDelegate: AnyObject {
func valueDidChange(_ feedMetadata: WebFeedMetadata, key: WebFeedMetadata.CodingKeys)
protocol FeedMetadataDelegate: AnyObject {
func valueDidChange(_ feedMetadata: FeedMetadata, key: FeedMetadata.CodingKeys)
}
final class WebFeedMetadata: Codable {
final class FeedMetadata: Codable {
enum CodingKeys: String, CodingKey {
case webFeedID = "feedID"
case feedID = "feedID"
case homePageURL
case iconURL
case faviconURL
@@ -33,10 +33,10 @@ final class WebFeedMetadata: Codable {
case isSyncingPaused
}
var webFeedID: String {
var feedID: String {
didSet {
if webFeedID != oldValue {
valueDidChange(.webFeedID)
if feedID != oldValue {
valueDidChange(.feedID)
}
}
}
@@ -146,10 +146,10 @@ final class WebFeedMetadata: Codable {
}
}
weak var delegate: WebFeedMetadataDelegate?
weak var delegate: FeedMetadataDelegate?
init(webFeedID: String) {
self.webFeedID = webFeedID
self.feedID = webFeedID
}
func valueDidChange(_ key: CodingKeys) {

View File

@@ -1,5 +1,5 @@
//
// WebFeedMetadataFile.swift
// FeedMetadataFile.swift
// Account
//
// Created by Maurice Parker on 9/13/19.
@@ -9,7 +9,7 @@
import Foundation
import RSCore
final class WebFeedMetadataFile: Logging {
final class FeedMetadataFile: Logging {
private let fileURL: URL
private let account: Account
@@ -33,9 +33,9 @@ final class WebFeedMetadataFile: Logging {
func load() {
if let fileData = try? Data(contentsOf: fileURL) {
let decoder = PropertyListDecoder()
account.webFeedMetadata = (try? decoder.decode(Account.WebFeedMetadataDictionary.self, from: fileData)) ?? Account.WebFeedMetadataDictionary()
account.feedMetadata = (try? decoder.decode(Account.FeedMetadataDictionary.self, from: fileData)) ?? Account.FeedMetadataDictionary()
}
account.webFeedMetadata.values.forEach { $0.delegate = account }
account.feedMetadata.values.forEach { $0.delegate = account }
}
func save() {
@@ -56,7 +56,7 @@ final class WebFeedMetadataFile: Logging {
}
private extension WebFeedMetadataFile {
private extension FeedMetadataFile {
func queueSaveToDiskIfNeeded() {
saveQueue.add(self, #selector(saveToDiskIfNeeded))
@@ -69,10 +69,10 @@ private extension WebFeedMetadataFile {
}
}
private func metadataForOnlySubscribedToFeeds() -> Account.WebFeedMetadataDictionary {
let webFeedIDs = account.idToWebFeedDictionary.keys
return account.webFeedMetadata.filter { (feedID: String, metadata: WebFeedMetadata) -> Bool in
return webFeedIDs.contains(metadata.webFeedID)
private func metadataForOnlySubscribedToFeeds() -> Account.FeedMetadataDictionary {
let feedIDs = account.idToWebFeedDictionary.keys
return account.feedMetadata.filter { (feedID: String, metadata: FeedMetadata) -> Bool in
return feedIDs.contains(metadata.feedID)
}
}

View File

@@ -366,7 +366,7 @@ final class FeedbinAccountDelegate: AccountDelegate, Logging {
switch result {
case .success:
DispatchQueue.main.async {
account.clearWebFeedMetadata(feed)
account.clearFeedMetadata(feed)
}
case .failure(let error):
self.logger.error("Remove feed error: \(error.localizedDescription, privacy: .public)")
@@ -1410,7 +1410,7 @@ private extension FeedbinAccountDelegate {
func complete() {
DispatchQueue.main.async {
account.clearWebFeedMetadata(feed)
account.clearFeedMetadata(feed)
account.removeWebFeed(feed)
if let folders = account.folders {
for folder in folders {

View File

@@ -542,7 +542,7 @@ extension NewsBlurAccountDelegate {
}
if account.existingWebFeed(withWebFeedID: feedID) != nil {
account.clearWebFeedMetadata(feed)
account.clearFeedMetadata(feed)
}
completion(.success(()))

View File

@@ -356,7 +356,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate, Logging {
switch result {
case .success:
DispatchQueue.main.async {
account.clearWebFeedMetadata(feed)
account.clearFeedMetadata(feed)
}
case .failure(let error):
self.logger.error("Remove feed error: \(error.localizedDescription, privacy: .public)")
@@ -476,7 +476,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate, Logging {
switch result {
case .success:
DispatchQueue.main.async {
account.clearWebFeedMetadata(feed)
account.clearFeedMetadata(feed)
account.removeWebFeed(feed)
if let folders = account.folders {
for folder in folders {
@@ -767,7 +767,7 @@ private extension ReaderAPIAccountDelegate {
for feed in account.topLevelWebFeeds {
if !subFeedIds.contains(feed.webFeedID) {
account.clearWebFeedMetadata(feed)
account.clearFeedMetadata(feed)
account.removeWebFeed(feed)
}
}

View File

@@ -30,10 +30,10 @@ public final class WebFeed: FeedProtocol, Renamable, Hashable, ObservableObject
public var webFeedID: String {
get {
return metadata.webFeedID
return metadata.feedID
}
set {
metadata.webFeedID = newValue
metadata.feedID = newValue
}
}
@@ -247,7 +247,7 @@ public final class WebFeed: FeedProtocol, Renamable, Hashable, ObservableObject
#endif
}
var metadata: WebFeedMetadata
var metadata: FeedMetadata
// MARK: - Private
@@ -255,7 +255,7 @@ public final class WebFeed: FeedProtocol, Renamable, Hashable, ObservableObject
// MARK: - Init
init(account: Account, url: String, metadata: WebFeedMetadata) {
init(account: Account, url: String, metadata: FeedMetadata) {
self.account = account
self.accountID = account.accountID
self.url = url

View File

@@ -230,7 +230,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
mainWindowController?.window?.center()
}
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
DispatchQueue.main.async {
@@ -403,10 +403,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
}
@MainActor @objc func webFeedSettingDidChange(_ note: Notification) {
guard let feed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.WebFeedSettingUserInfoKey] as? String else {
guard let feed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.FeedSettingUserInfoKey] as? String else {
return
}
if key == WebFeed.WebFeedSettingKey.homePageURL || key == WebFeed.WebFeedSettingKey.faviconURL {
if key == WebFeed.FeedSettingKey.homePageURL || key == WebFeed.FeedSettingKey.faviconURL {
let _ = faviconDownloader.favicon(for: feed)
}
}

View File

@@ -32,7 +32,7 @@ extension SidebarViewController {
switch object {
case is WebFeed:
return menuForWebFeed(object as! WebFeed)
return menuForFeed(object as! WebFeed)
case is Folder:
return menuForFolder(object as! Folder)
case is PseudoFeed:
@@ -264,7 +264,7 @@ private extension SidebarViewController {
return menu
}
func menuForWebFeed(_ webFeed: WebFeed) -> NSMenu? {
func menuForFeed(_ webFeed: WebFeed) -> NSMenu? {
let menu = NSMenu(title: "")

View File

@@ -79,7 +79,7 @@ protocol SidebarDelegate: AnyObject {
NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(webFeedIconDidBecomeAvailable(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
DistributedNotificationCenter.default().addObserver(self, selector: #selector(appleSideBarDefaultIconSizeChanged(_:)), name: .appleSideBarDefaultIconSizeChanged, object: nil)
@@ -202,10 +202,10 @@ protocol SidebarDelegate: AnyObject {
}
@objc func webFeedSettingDidChange(_ note: Notification) {
guard let webFeed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.WebFeedSettingUserInfoKey] as? String else {
guard let webFeed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.FeedSettingUserInfoKey] as? String else {
return
}
if key == WebFeed.WebFeedSettingKey.homePageURL || key == WebFeed.WebFeedSettingKey.faviconURL {
if key == WebFeed.FeedSettingKey.homePageURL || key == WebFeed.FeedSettingKey.faviconURL {
configureCellsForRepresentedObject(webFeed)
}
}

View File

@@ -71,7 +71,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner, Ma
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(webFeedIconDidBecomeAvailable(_:)), name: .WebFeedIconDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
@@ -151,10 +151,10 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner, Ma
}
@objc func webFeedSettingDidChange(_ note: Notification) {
guard let webFeed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.WebFeedSettingUserInfoKey] as? String else {
guard let webFeed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.FeedSettingUserInfoKey] as? String else {
return
}
if key == WebFeed.WebFeedSettingKey.homePageURL || key == WebFeed.WebFeedSettingKey.faviconURL {
if key == WebFeed.FeedSettingKey.homePageURL || key == WebFeed.FeedSettingKey.faviconURL {
configureCellsForRepresentedObject(webFeed)
}
}