diff --git a/Mac/AppDefaults.swift b/Mac/AppDefaults.swift index 076ffb272..973b45269 100644 --- a/Mac/AppDefaults.swift +++ b/Mac/AppDefaults.swift @@ -35,8 +35,8 @@ final class AppDefaults { static let subscribeToFeedsInDefaultBrowser = "subscribeToFeedsInDefaultBrowser" static let articleTextSize = "articleTextSize" static let refreshInterval = "refreshInterval" - static let addWebFeedAccountID = "addWebFeedAccountID" - static let addWebFeedFolderName = "addWebFeedFolderName" + static let addFeedAccountID = "addFeedAccountID" + static let addFeedFolderName = "addFeedFolderName" static let addFolderAccountID = "addFolderAccountID" static let importOPMLAccountID = "importOPMLAccountID" static let exportOPMLAccountID = "exportOPMLAccountID" @@ -159,21 +159,21 @@ final class AppDefaults { } } - var addWebFeedAccountID: String? { + var addFeedAccountID: String? { get { - return AppDefaults.string(for: Key.addWebFeedAccountID) + return AppDefaults.string(for: Key.addFeedAccountID) } set { - AppDefaults.setString(for: Key.addWebFeedAccountID, newValue) + AppDefaults.setString(for: Key.addFeedAccountID, newValue) } } - var addWebFeedFolderName: String? { + var addFeedFolderName: String? { get { - return AppDefaults.string(for: Key.addWebFeedFolderName) + return AppDefaults.string(for: Key.addFeedFolderName) } set { - AppDefaults.setString(for: Key.addWebFeedFolderName, newValue) + AppDefaults.setString(for: Key.addFeedFolderName, newValue) } } diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 2fc958191..51aa2bdd9 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -134,9 +134,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat addFolderWindowController!.runSheetOnWindow(window) } - func showAddWebFeedSheetOnWindow(_ window: NSWindow, urlString: String?, name: String?, account: Account?, folder: Folder?) { + func showAddFeedSheetOnWindow(_ window: NSWindow, urlString: String?, name: String?, account: Account?, folder: Folder?) { addFeedController = AddFeedController(hostWindow: window) - addFeedController?.showAddFeedSheet(.webFeed, urlString, name, account, folder) + addFeedController?.showAddFeedSheet(urlString, name, account, folder) } // MARK: - NSApplicationDelegate @@ -207,7 +207,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat mainWindowController?.window?.center() } - NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .feedSettingDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil) DispatchQueue.main.async { @@ -331,11 +331,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat } } - @objc func webFeedSettingDidChange(_ note: Notification) { - guard let feed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.WebFeedSettingUserInfoKey] as? String else { + @objc func feedSettingDidChange(_ note: Notification) { + guard let feed = note.object as? Feed, let key = note.userInfo?[Feed.SettingUserInfoKey] as? String else { return } - if key == WebFeed.WebFeedSettingKey.homePageURL || key == WebFeed.WebFeedSettingKey.faviconURL { + if key == Feed.SettingKey.homePageURL || key == Feed.SettingKey.faviconURL { _ = FaviconDownloader.shared.favicon(for: feed) } } @@ -444,7 +444,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat return mainWindowController?.isOpen ?? false } - if item.action == #selector(showAddWebFeedWindow(_:)) || item.action == #selector(showAddFolderWindow(_:)) { + if item.action == #selector(showAddFeedWindow(_:)) || item.action == #selector(showAddFolderWindow(_:)) { return !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty } @@ -477,14 +477,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat } // MARK: Add Feed - func addWebFeed(_ urlString: String?, name: String? = nil, account: Account? = nil, folder: Folder? = nil) { + func addFeed(_ urlString: String?, name: String? = nil, account: Account? = nil, folder: Folder? = nil) { createAndShowMainWindowIfNecessary() if mainWindowController!.isDisplayingSheet { return } - showAddWebFeedSheetOnWindow(mainWindowController!.window!, urlString: urlString, name: name, account: account, folder: folder) + showAddFeedSheetOnWindow(mainWindowController!.window!, urlString: urlString, name: name, account: account, folder: folder) } // MARK: - Dock Badge @@ -517,8 +517,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat AccountManager.shared.refreshAll(errorHandler: ErrorHandler.present) } - @IBAction func showAddWebFeedWindow(_ sender: Any?) { - addWebFeed(nil) + @IBAction func showAddFeedWindow(_ sender: Any?) { + addFeed(nil) } @IBAction func showAddFolderWindow(_ sender: Any?) { @@ -591,7 +591,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat if AccountManager.shared.anyAccountHasNetNewsWireNewsSubscription() { return } - addWebFeed(AccountManager.netNewsWireNewsURL, name: "NetNewsWire News") + addFeed(AccountManager.netNewsWireNewsURL, name: "NetNewsWire News") } @IBAction func openWebsite(_ sender: Any?) { diff --git a/Mac/Base.lproj/AddWebFeedSheet.xib b/Mac/Base.lproj/AddFeedSheet.xib similarity index 85% rename from Mac/Base.lproj/AddWebFeedSheet.xib rename to Mac/Base.lproj/AddFeedSheet.xib index 3bc63e0be..62d55fa53 100644 --- a/Mac/Base.lproj/AddWebFeedSheet.xib +++ b/Mac/Base.lproj/AddFeedSheet.xib @@ -1,11 +1,11 @@ - + - + - + @@ -16,25 +16,25 @@ - + - + - + - - + + - - + + @@ -48,24 +48,24 @@ - - + + - - + + - - + + @@ -73,10 +73,10 @@ - + - + @@ -87,7 +87,7 @@ - + @@ -169,7 +168,7 @@ Field - + @@ -221,7 +220,7 @@ Field - + @@ -256,7 +255,7 @@ Field - + @@ -264,7 +263,7 @@ Field - + diff --git a/Mac/MainWindow/AddFeed/AddFeedController.swift b/Mac/MainWindow/AddFeed/AddFeedController.swift index 105fae366..b3b1f0200 100644 --- a/Mac/MainWindow/AddFeed/AddFeedController.swift +++ b/Mac/MainWindow/AddFeed/AddFeedController.swift @@ -33,21 +33,18 @@ final class AddFeedController: AddFeedWindowControllerDelegate { self.hostWindow = hostWindow } - func showAddFeedSheet(_ type: AddFeedWindowControllerType, _ urlString: String? = nil, _ name: String? = nil, _ account: Account? = nil, _ folder: Folder? = nil) { + func showAddFeedSheet(_ urlString: String? = nil, _ name: String? = nil, _ account: Account? = nil, _ folder: Folder? = nil) { let folderTreeControllerDelegate = FolderTreeControllerDelegate() let folderTreeController = TreeController(delegate: folderTreeControllerDelegate) - switch type { - case .webFeed: - addFeedWindowController = AddWebFeedWindowController(urlString: urlString ?? urlStringFromPasteboard, - name: name, - account: account, - folder: folder, - folderTreeController: folderTreeController, - delegate: self) - } - - addFeedWindowController!.runSheetOnWindow(hostWindow) + let windowController = AddFeedWindowController(urlString: urlString ?? urlStringFromPasteboard, + name: name, + account: account, + folder: folder, + folderTreeController: folderTreeController, + delegate: self) + addFeedWindowController = windowController + windowController.runSheetOnWindow(hostWindow) } // MARK: AddFeedWindowControllerDelegate @@ -60,12 +57,12 @@ final class AddFeedController: AddFeedWindowControllerDelegate { } let account = accountAndFolderSpecifier.account - if account.hasWebFeed(withURL: url.absoluteString) { + if account.hasFeed(withURL: url.absoluteString) { showAlreadySubscribedError(url.absoluteString) return } - account.createWebFeed(url: url.absoluteString, name: title, container: container, validateFeed: true) { result in + account.createFeed(url: url.absoluteString, name: title, container: container, validateFeed: true) { result in DispatchQueue.main.async { self.endShowingProgress() @@ -73,7 +70,7 @@ final class AddFeedController: AddFeedWindowControllerDelegate { switch result { case .success(let feed): - NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.webFeed: feed]) + NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed]) case .failure(let error): switch error { case AccountError.createErrorAlreadySubscribed: diff --git a/Mac/MainWindow/AddFeed/AddFeedWIndowController.swift b/Mac/MainWindow/AddFeed/AddFeedWIndowController.swift deleted file mode 100644 index a362c9d3f..000000000 --- a/Mac/MainWindow/AddFeed/AddFeedWIndowController.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// AddFeedWIndowController.swift -// NetNewsWire -// -// Created by Maurice Parker on 4/21/20. -// Copyright © 2020 Ranchero Software. All rights reserved. -// - -import Foundation -import Account - -enum AddFeedWindowControllerType { - case webFeed -} - -protocol AddFeedWindowControllerDelegate: AnyObject { - - // userEnteredURL will have already been validated and normalized. - func addFeedWindowController(_: AddFeedWindowController, userEnteredURL: URL, userEnteredTitle: String?, container: Container) - func addFeedWindowControllerUserDidCancel(_: AddFeedWindowController) - -} - -protocol AddFeedWindowController { - - var window: NSWindow? { get } - func runSheetOnWindow(_ hostWindow: NSWindow) - -} diff --git a/Mac/MainWindow/AddFeed/AddWebFeedWindowController.swift b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift similarity index 85% rename from Mac/MainWindow/AddFeed/AddWebFeedWindowController.swift rename to Mac/MainWindow/AddFeed/AddFeedWindowController.swift index 6ca31a78d..75446789c 100644 --- a/Mac/MainWindow/AddFeed/AddWebFeedWindowController.swift +++ b/Mac/MainWindow/AddFeed/AddFeedWindowController.swift @@ -12,7 +12,13 @@ import RSTree import Articles import Account -final class AddWebFeedWindowController : NSWindowController, AddFeedWindowController { +protocol AddFeedWindowControllerDelegate: AnyObject { + // userEnteredURL will have already been validated and normalized. + func addFeedWindowController(_: AddFeedWindowController, userEnteredURL: URL, userEnteredTitle: String?, container: Container) + func addFeedWindowControllerUserDidCancel(_: AddFeedWindowController) +} + +final class AddFeedWindowController : NSWindowController { @IBOutlet var urlTextField: NSTextField! @IBOutlet var nameTextField: NSTextField! @@ -38,7 +44,7 @@ final class AddWebFeedWindowController : NSWindowController, AddFeedWindowContro var hostWindow: NSWindow! convenience init(urlString: String?, name: String?, account: Account?, folder: Folder?, folderTreeController: TreeController, delegate: AddFeedWindowControllerDelegate?) { - self.init(windowNibName: NSNib.Name("AddWebFeedSheet")) + self.init(windowNibName: NSNib.Name("AddFeedSheet")) self.urlString = urlString self.initialName = name self.initialAccount = account @@ -67,7 +73,7 @@ final class AddWebFeedWindowController : NSWindowController, AddFeedWindowContro if let account = initialAccount { FolderTreeMenu.select(account: account, folder: initialFolder, in: folderPopupButton) - } else if let container = AddWebFeedDefaultContainer.defaultContainer { + } else if let container = AddFeedDefaultContainer.defaultContainer { if let folder = container as? Folder, let account = folder.account { FolderTreeMenu.select(account: account, folder: folder, in: folderPopupButton) } else { @@ -100,7 +106,7 @@ final class AddWebFeedWindowController : NSWindowController, AddFeedWindowContro } guard let container = selectedContainer() else { return } - AddWebFeedDefaultContainer.saveDefaultContainer(container) + AddFeedDefaultContainer.saveDefaultContainer(container) delegate?.addFeedWindowController(self, userEnteredURL: url, userEnteredTitle: userEnteredTitle, container: container) @@ -122,7 +128,7 @@ final class AddWebFeedWindowController : NSWindowController, AddFeedWindowContro } } -private extension AddWebFeedWindowController { +private extension AddFeedWindowController { private func updateUI() { addButton.isEnabled = urlTextField.stringValue.mayBeURL && selectedContainer() != nil diff --git a/Mac/MainWindow/Detail/DetailWebViewController.swift b/Mac/MainWindow/Detail/DetailWebViewController.swift index af3d5bd81..f314f5172 100644 --- a/Mac/MainWindow/Detail/DetailWebViewController.swift +++ b/Mac/MainWindow/Detail/DetailWebViewController.swift @@ -108,7 +108,7 @@ final class DetailWebViewController: NSViewController { webInspectorEnabled = AppDefaults.shared.webInspectorEnabled NotificationCenter.default.addObserver(self, selector: #selector(webInspectorEnabledDidChange(_:)), name: .WebInspectorEnabledDidChange, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(webFeedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil) @@ -119,7 +119,7 @@ final class DetailWebViewController: NSViewController { // MARK: Notifications - @objc func webFeedIconDidBecomeAvailable(_ note: Notification) { + @objc func feedIconDidBecomeAvailable(_ note: Notification) { reloadArticleImage() } diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index cb6f4a8f6..0bc9eb9e2 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -180,7 +180,7 @@ final class MainWindowController : NSWindowController, NSUserInterfaceValidation } } - if let feed = currentFeedOrFolder as? WebFeed, let noteObject = noteObject as? WebFeed { + if let feed = currentFeedOrFolder as? Feed, let noteObject = noteObject as? Feed { if feed == noteObject { updateWindowTitle() return @@ -611,7 +611,7 @@ extension MainWindowController: TimelineContainerViewControllerDelegate { if let articles = articles { if articles.count == 1 { activityManager.reading(feed: nil, article: articles.first) - if articles.first?.webFeed?.isArticleExtractorAlwaysOn ?? false { + if articles.first?.feed?.isArticleExtractorAlwaysOn ?? false { detailState = .loading startArticleExtractorForCurrentLink() } else { @@ -628,8 +628,8 @@ extension MainWindowController: TimelineContainerViewControllerDelegate { detailViewController?.setState(detailState, mode: mode) } - func timelineRequestedWebFeedSelection(_: TimelineContainerViewController, webFeed: WebFeed) { - sidebarViewController?.selectFeed(webFeed) + func timelineRequestedFeedSelection(_: TimelineContainerViewController, feed: Feed) { + sidebarViewController?.selectFeed(feed) } func timelineInvalidatedRestorationState(_: TimelineContainerViewController) { @@ -1124,7 +1124,7 @@ private extension MainWindowController { return currentLink != nil } - if currentTimelineViewController?.selectedArticles.first?.webFeed != nil { + if currentTimelineViewController?.selectedArticles.first?.feed != nil { toolbarButton.isEnabled = true } @@ -1384,10 +1384,10 @@ private extension MainWindowController { func buildNewSidebarItemMenu() -> NSMenu { let menu = NSMenu() - let newWebFeedItem = NSMenuItem() - newWebFeedItem.title = NSLocalizedString("New Feed…", comment: "New Feed") - newWebFeedItem.action = Selector(("showAddWebFeedWindow:")) - menu.addItem(newWebFeedItem) + let newFeedItem = NSMenuItem() + newFeedItem.title = NSLocalizedString("New Feed…", comment: "New Feed") + newFeedItem.action = Selector(("showAddFeedWindow:")) + menu.addItem(newFeedItem) let newFolderFeedItem = NSMenuItem() newFolderFeedItem.title = NSLocalizedString("New Folder…", comment: "New Folder") diff --git a/Mac/MainWindow/Sidebar/PasteboardWebFeed.swift b/Mac/MainWindow/Sidebar/PasteboardFeed.swift similarity index 50% rename from Mac/MainWindow/Sidebar/PasteboardWebFeed.swift rename to Mac/MainWindow/Sidebar/PasteboardFeed.swift index 75e2239a0..d8a1735d2 100644 --- a/Mac/MainWindow/Sidebar/PasteboardWebFeed.swift +++ b/Mac/MainWindow/Sidebar/PasteboardFeed.swift @@ -11,9 +11,9 @@ import Articles import Account import RSCore -typealias PasteboardWebFeedDictionary = [String: String] +typealias PasteboardFeedDictionary = [String: String] -struct PasteboardWebFeed: Hashable { +struct PasteboardFeed: Hashable { fileprivate struct Key { static let url = "URL" @@ -23,13 +23,13 @@ struct PasteboardWebFeed: Hashable { // Internal static let accountID = "accountID" static let accountType = "accountType" - static let webFeedID = "webFeedID" + static let feedID = "feedID" static let editedName = "editedName" static let containerName = "containerName" } let url: String - let webFeedID: String? + let feedID: String? let homePageURL: String? let name: String? let editedName: String? @@ -38,9 +38,9 @@ struct PasteboardWebFeed: Hashable { let containerName: String? let isLocalFeed: Bool - init(url: String, webFeedID: String?, homePageURL: String?, name: String?, editedName: String?, accountID: String?, accountType: AccountType?, containerName: String? = nil) { + init(url: String, feedID: String?, homePageURL: String?, name: String?, editedName: String?, accountID: String?, accountType: AccountType?, containerName: String? = nil) { self.url = url.normalizedURL - self.webFeedID = webFeedID + self.feedID = feedID self.homePageURL = homePageURL?.normalizedURL self.name = name self.editedName = editedName @@ -52,7 +52,7 @@ struct PasteboardWebFeed: Hashable { // MARK: - Reading - init?(dictionary: PasteboardWebFeedDictionary) { + init?(dictionary: PasteboardFeedDictionary) { guard let url = dictionary[Key.url] else { return nil } @@ -60,7 +60,7 @@ struct PasteboardWebFeed: Hashable { let homePageURL = dictionary[Key.homePageURL] let name = dictionary[Key.name] let accountID = dictionary[Key.accountID] - let webFeedID = dictionary[Key.webFeedID] + let feedID = dictionary[Key.feedID] let editedName = dictionary[Key.editedName] var accountType: AccountType? = nil @@ -69,19 +69,19 @@ struct PasteboardWebFeed: Hashable { } let containerName = dictionary[Key.containerName] - self.init(url: url, webFeedID: webFeedID, homePageURL: homePageURL, name: name, editedName: editedName, accountID: accountID, accountType: accountType, containerName: containerName) + self.init(url: url, feedID: feedID, homePageURL: homePageURL, name: name, editedName: editedName, accountID: accountID, accountType: accountType, containerName: containerName) } init?(pasteboardItem: NSPasteboardItem) { var pasteboardType: NSPasteboard.PasteboardType? - if pasteboardItem.types.contains(WebFeedPasteboardWriter.webFeedUTIInternalType) { - pasteboardType = WebFeedPasteboardWriter.webFeedUTIInternalType + if pasteboardItem.types.contains(FeedPasteboardWriter.feedUTIInternalType) { + pasteboardType = FeedPasteboardWriter.feedUTIInternalType } - else if pasteboardItem.types.contains(WebFeedPasteboardWriter.webFeedUTIType) { - pasteboardType = WebFeedPasteboardWriter.webFeedUTIType + else if pasteboardItem.types.contains(FeedPasteboardWriter.feedUTIType) { + pasteboardType = FeedPasteboardWriter.feedUTIType } if let foundType = pasteboardType { - if let feedDictionary = pasteboardItem.propertyList(forType: foundType) as? PasteboardWebFeedDictionary { + if let feedDictionary = pasteboardItem.propertyList(forType: foundType) as? PasteboardFeedDictionary { self.init(dictionary: feedDictionary) return } @@ -98,7 +98,7 @@ struct PasteboardWebFeed: Hashable { if let foundType = pasteboardType { if let possibleURLString = pasteboardItem.string(forType: foundType) { if possibleURLString.mayBeURL { - self.init(url: possibleURLString, webFeedID: nil, homePageURL: nil, name: nil, editedName: nil, accountID: nil, accountType: nil) + self.init(url: possibleURLString, feedID: nil, homePageURL: nil, name: nil, editedName: nil, accountID: nil, accountType: nil) return } } @@ -107,18 +107,18 @@ struct PasteboardWebFeed: Hashable { return nil } - static func pasteboardFeeds(with pasteboard: NSPasteboard) -> Set? { + static func pasteboardFeeds(with pasteboard: NSPasteboard) -> Set? { guard let items = pasteboard.pasteboardItems else { return nil } - let webFeeds = items.compactMap { PasteboardWebFeed(pasteboardItem: $0) } - return webFeeds.isEmpty ? nil : Set(webFeeds) + let feeds = items.compactMap { PasteboardFeed(pasteboardItem: $0) } + return feeds.isEmpty ? nil : Set(feeds) } // MARK: - Writing - func exportDictionary() -> PasteboardWebFeedDictionary { - var d = PasteboardWebFeedDictionary() + func exportDictionary() -> PasteboardFeedDictionary { + var d = PasteboardFeedDictionary() d[Key.url] = url d[Key.homePageURL] = homePageURL ?? "" if let nameForDisplay = editedName ?? name { @@ -127,58 +127,58 @@ struct PasteboardWebFeed: Hashable { return d } - func internalDictionary() -> PasteboardWebFeedDictionary { - var d = PasteboardWebFeedDictionary() - d[PasteboardWebFeed.Key.webFeedID] = webFeedID - d[PasteboardWebFeed.Key.url] = url + func internalDictionary() -> PasteboardFeedDictionary { + var d = PasteboardFeedDictionary() + d[PasteboardFeed.Key.feedID] = feedID + d[PasteboardFeed.Key.url] = url if let homePageURL = homePageURL { - d[PasteboardWebFeed.Key.homePageURL] = homePageURL + d[PasteboardFeed.Key.homePageURL] = homePageURL } if let name = name { - d[PasteboardWebFeed.Key.name] = name + d[PasteboardFeed.Key.name] = name } if let editedName = editedName { - d[PasteboardWebFeed.Key.editedName] = editedName + d[PasteboardFeed.Key.editedName] = editedName } if let accountID = accountID { - d[PasteboardWebFeed.Key.accountID] = accountID + d[PasteboardFeed.Key.accountID] = accountID } if let accountType = accountType { - d[PasteboardWebFeed.Key.accountType] = String(accountType.rawValue) + d[PasteboardFeed.Key.accountType] = String(accountType.rawValue) } if let containerName = containerName { - d[PasteboardWebFeed.Key.containerName] = containerName + d[PasteboardFeed.Key.containerName] = containerName } return d } } -extension WebFeed: @retroactive PasteboardWriterOwner { +extension Feed: @retroactive PasteboardWriterOwner { public var pasteboardWriter: NSPasteboardWriting { - return WebFeedPasteboardWriter(webFeed: self) + return FeedPasteboardWriter(feed: self) } } -@objc final class WebFeedPasteboardWriter: NSObject, NSPasteboardWriting { +@objc final class FeedPasteboardWriter: NSObject, NSPasteboardWriting { - private let webFeed: WebFeed - static let webFeedUTI = "com.ranchero.webFeed" - static let webFeedUTIType = NSPasteboard.PasteboardType(rawValue: webFeedUTI) - static let webFeedUTIInternal = "com.ranchero.NetNewsWire-Evergreen.internal.webFeed" - static let webFeedUTIInternalType = NSPasteboard.PasteboardType(rawValue: webFeedUTIInternal) + private let feed: Feed + static let feedUTI = "com.ranchero.feed" + static let feedUTIType = NSPasteboard.PasteboardType(rawValue: feedUTI) + static let feedUTIInternal = "com.ranchero.NetNewsWire-Evergreen.internal.feed" + static let feedUTIInternalType = NSPasteboard.PasteboardType(rawValue: feedUTIInternal) var containerID: ContainerIdentifier? = nil - init(webFeed: WebFeed) { - self.webFeed = webFeed + init(feed: Feed) { + self.feed = feed } // MARK: - NSPasteboardWriting func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] { - return [WebFeedPasteboardWriter.webFeedUTIType, .URL, .string, WebFeedPasteboardWriter.webFeedUTIInternalType] + return [FeedPasteboardWriter.feedUTIType, .URL, .string, FeedPasteboardWriter.feedUTIInternalType] } func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? { @@ -187,12 +187,12 @@ extension WebFeed: @retroactive PasteboardWriterOwner { switch type { case .string: - plist = webFeed.nameForDisplay + plist = feed.nameForDisplay case .URL: - plist = webFeed.url - case WebFeedPasteboardWriter.webFeedUTIType: + plist = feed.url + case FeedPasteboardWriter.feedUTIType: plist = exportDictionary - case WebFeedPasteboardWriter.webFeedUTIInternalType: + case FeedPasteboardWriter.feedUTIInternalType: plist = internalDictionary default: plist = nil @@ -202,22 +202,22 @@ extension WebFeed: @retroactive PasteboardWriterOwner { } } -private extension WebFeedPasteboardWriter { +private extension FeedPasteboardWriter { - var pasteboardFeed: PasteboardWebFeed { - return PasteboardWebFeed(url: webFeed.url, webFeedID: webFeed.webFeedID, homePageURL: webFeed.homePageURL, name: webFeed.name, editedName: webFeed.editedName, accountID: webFeed.account?.accountID, accountType: webFeed.account?.type) + var pasteboardFeed: PasteboardFeed { + return PasteboardFeed(url: feed.url, feedID: feed.feedID, homePageURL: feed.homePageURL, name: feed.name, editedName: feed.editedName, accountID: feed.account?.accountID, accountType: feed.account?.type) } - var exportDictionary: PasteboardWebFeedDictionary { + var exportDictionary: PasteboardFeedDictionary { return pasteboardFeed.exportDictionary() } - var internalDictionary: PasteboardWebFeedDictionary { + var internalDictionary: PasteboardFeedDictionary { var dictionary = pasteboardFeed.internalDictionary() - if dictionary[PasteboardWebFeed.Key.containerName] == nil, + if dictionary[PasteboardFeed.Key.containerName] == nil, case let .folder(accountID, folderName) = containerID { - assert(accountID == dictionary[PasteboardWebFeed.Key.accountID], "unexpected: container account doesn't match account of contained item") - dictionary[PasteboardWebFeed.Key.containerName] = folderName + assert(accountID == dictionary[PasteboardFeed.Key.accountID], "unexpected: container account doesn't match account of contained item") + dictionary[PasteboardFeed.Key.containerName] = folderName } return dictionary } diff --git a/Mac/MainWindow/Sidebar/PasteboardFolder.swift b/Mac/MainWindow/Sidebar/PasteboardFolder.swift index 0ffd6c08b..0d8f1cc33 100644 --- a/Mac/MainWindow/Sidebar/PasteboardFolder.swift +++ b/Mac/MainWindow/Sidebar/PasteboardFolder.swift @@ -52,7 +52,7 @@ struct PasteboardFolder: Hashable { } if let foundType = pasteboardType { - if let folderDictionary = pasteboardItem.propertyList(forType: foundType) as? PasteboardWebFeedDictionary { + if let folderDictionary = pasteboardItem.propertyList(forType: foundType) as? PasteboardFeedDictionary { self.init(dictionary: folderDictionary) return } @@ -72,7 +72,7 @@ struct PasteboardFolder: Hashable { // MARK: - Writing func internalDictionary() -> PasteboardFolderDictionary { - var d = PasteboardWebFeedDictionary() + var d = PasteboardFeedDictionary() d[PasteboardFolder.Key.name] = name if let folderID = folderID { d[PasteboardFolder.Key.folderID] = folderID @@ -131,7 +131,7 @@ private extension FolderPasteboardWriter { return PasteboardFolder(name: folder.name ?? "", folderID: String(folder.folderID), accountID: folder.account?.accountID) } - var internalDictionary: PasteboardWebFeedDictionary { + var internalDictionary: PasteboardFeedDictionary { return pasteboardFolder.internalDictionary() } } diff --git a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift index 7e0478d5f..4b1c762c3 100644 --- a/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift +++ b/Mac/MainWindow/Sidebar/SidebarOutlineDataSource.swift @@ -47,10 +47,10 @@ import Account return nil } - // WebFeed objects don't have knowledge of their parent so we inject parent container information - // into WebFeedPasteboardWriter instance and it adds this field to the PasteboardWebFeed objects it writes. + // Feed objects don't have knowledge of their parent so we inject parent container information + // into FeedPasteboardWriter instance and it adds this field to the PasteboardFeed objects it writes. // Add similar to FolderPasteboardWriter if/when we allow sub-folders - if let feedWriter = pasteboardWriter as? WebFeedPasteboardWriter { + if let feedWriter = pasteboardWriter as? FeedPasteboardWriter { if let parentContainerID = (node.parent?.representedObject as? Folder)?.containerID { feedWriter.containerID = parentContainerID pasteboardWriter = feedWriter @@ -63,7 +63,7 @@ import Account func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { let draggedFolders = PasteboardFolder.pasteboardFolders(with: info.draggingPasteboard) - let draggedFeeds = PasteboardWebFeed.pasteboardFeeds(with: info.draggingPasteboard) + let draggedFeeds = PasteboardFeed.pasteboardFeeds(with: info.draggingPasteboard) if (draggedFolders == nil && draggedFeeds == nil) || (draggedFolders != nil && draggedFeeds != nil) { return SidebarOutlineDataSource.dragOperationNone } @@ -99,7 +99,7 @@ import Account func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool { let draggedFolders = PasteboardFolder.pasteboardFolders(with: info.draggingPasteboard) - let draggedFeeds = PasteboardWebFeed.pasteboardFeeds(with: info.draggingPasteboard) + let draggedFeeds = PasteboardFeed.pasteboardFeeds(with: info.draggingPasteboard) if (draggedFolders == nil && draggedFeeds == nil) || (draggedFolders != nil && draggedFeeds != nil) { return false } @@ -144,7 +144,7 @@ private extension SidebarOutlineDataSource { // Don’t allow PseudoFeed to be dragged. // This will have to be revisited later. For instance, // user-created smart feeds should be draggable, maybe. - return node.representedObject is Folder || node.representedObject is WebFeed + return node.representedObject is Folder || node.representedObject is Feed } // MARK: - Drag and Drop @@ -153,7 +153,7 @@ private extension SidebarOutlineDataSource { case empty, singleLocal, singleNonLocal, multipleLocal, multipleNonLocal, mixed } - func draggedFeedContentsType(_ draggedFeeds: Set) -> DraggedFeedsContentsType { + func draggedFeedContentsType(_ draggedFeeds: Set) -> DraggedFeedsContentsType { if draggedFeeds.isEmpty { return .empty } @@ -181,14 +181,14 @@ private extension SidebarOutlineDataSource { return .multipleNonLocal } - func singleNonLocalFeed(from feeds: Set) -> PasteboardWebFeed? { + func singleNonLocalFeed(from feeds: Set) -> PasteboardFeed? { guard feeds.count == 1, let feed = feeds.first else { return nil } return feed.isLocalFeed ? nil : feed } - func validateSingleNonLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardWebFeed, _ parentNode: Node, _ index: Int) -> NSDragOperation { + func validateSingleNonLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardFeed, _ parentNode: Node, _ index: Int) -> NSDragOperation { // A non-local feed should always drag on to an Account or Folder node, with NSOutlineViewDropOnItemIndex — since we don’t know where it would sort till we read the feed. guard let dropTargetNode = ancestorThatCanAcceptNonLocalFeed(parentNode) else { return SidebarOutlineDataSource.dragOperationNone @@ -199,7 +199,7 @@ private extension SidebarOutlineDataSource { return .copy } - func validateSingleLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardWebFeed, _ parentNode: Node, _ index: Int) -> NSDragOperation { + func validateSingleLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardFeed, _ parentNode: Node, _ index: Int) -> NSDragOperation { // A local feed should always drag on to an Account or Folder node, and we can provide an index. guard let dropTargetNode = ancestorThatCanAcceptLocalFeed(parentNode) else { return SidebarOutlineDataSource.dragOperationNone @@ -220,7 +220,7 @@ private extension SidebarOutlineDataSource { return localDragOperation(parentNode: parentNode, Set([draggedFeed])) } - func validateLocalFeedsDrop(_ outlineView: NSOutlineView, _ draggedFeeds: Set, _ parentNode: Node, _ index: Int) -> NSDragOperation { + func validateLocalFeedsDrop(_ outlineView: NSOutlineView, _ draggedFeeds: Set, _ parentNode: Node, _ index: Int) -> NSDragOperation { // Local feeds should always drag on to an Account or Folder node, and index should be NSOutlineViewDropOnItemIndex since we can’t provide multiple indexes. guard let dropTargetNode = ancestorThatCanAcceptLocalFeed(parentNode) else { return SidebarOutlineDataSource.dragOperationNone @@ -237,7 +237,7 @@ private extension SidebarOutlineDataSource { return localDragOperation(parentNode: parentNode, draggedFeeds) } - func localDragOperation(parentNode: Node, _ draggedFeeds: Set)-> NSDragOperation { + func localDragOperation(parentNode: Node, _ draggedFeeds: Set)-> NSDragOperation { guard let firstDraggedFeed = draggedFeeds.first else { return .move } if sameAccount(firstDraggedFeed, parentNode) { if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false { @@ -257,7 +257,7 @@ private extension SidebarOutlineDataSource { if let folder = node.representedObject as? Folder { return folder.account } - if let feed = node.representedObject as? WebFeed { + if let feed = node.representedObject as? Feed { return feed.account } return nil @@ -315,8 +315,8 @@ private extension SidebarOutlineDataSource { return .copy // different AccountIDs means can only copy } - func copyWebFeedInAccount(_ feed: WebFeed, _ destination: Container ) { - destination.account?.addWebFeed(feed, to: destination) { result in + func copyFeedInAccount(_ feed: Feed, _ destination: Container ) { + destination.account?.addFeed(feed, to: destination) { result in switch result { case .success: break @@ -326,9 +326,9 @@ private extension SidebarOutlineDataSource { } } - func moveWebFeedInAccount(_ feed: WebFeed, _ source: Container, _ destination: Container) { + func moveFeedInAccount(_ feed: Feed, _ source: Container, _ destination: Container) { BatchUpdate.shared.start() - source.account?.moveWebFeed(feed, from: source, to: destination) { result in + source.account?.moveFeed(feed, from: source, to: destination) { result in BatchUpdate.shared.end() switch result { case .success: @@ -339,13 +339,13 @@ private extension SidebarOutlineDataSource { } } - func copyWebFeedBetweenAccounts(_ feed: WebFeed, _ destinationContainer: Container) { + func copyFeedBetweenAccounts(_ feed: Feed, _ destinationContainer: Container) { guard let destinationAccount = destinationContainer.account else { return } - if let existingFeed = destinationAccount.existingWebFeed(withURL: feed.url) { - destinationAccount.addWebFeed(existingFeed, to: destinationContainer) { result in + if let existingFeed = destinationAccount.existingFeed(withURL: feed.url) { + destinationAccount.addFeed(existingFeed, to: destinationContainer) { result in switch result { case .success: break @@ -354,7 +354,7 @@ private extension SidebarOutlineDataSource { } } } else { - destinationAccount.createWebFeed(url: feed.url, name: feed.nameForDisplay, container: destinationContainer, validateFeed: false) { result in + destinationAccount.createFeed(url: feed.url, name: feed.nameForDisplay, container: destinationContainer, validateFeed: false) { result in switch result { case .success: break @@ -365,7 +365,7 @@ private extension SidebarOutlineDataSource { } } - func acceptLocalFeedsDrop(_ outlineView: NSOutlineView, _ draggedFeeds: Set, _ parentNode: Node, _ index: Int) -> Bool { + func acceptLocalFeedsDrop(_ outlineView: NSOutlineView, _ draggedFeeds: Set, _ parentNode: Node, _ index: Int) -> Bool { guard draggedFeeds.isEmpty == false else { return false } @@ -373,8 +373,8 @@ private extension SidebarOutlineDataSource { draggedFeeds.forEach { pasteboardFeed in guard let sourceAccountID = pasteboardFeed.accountID, let sourceAccount = AccountManager.shared.existingAccount(with: sourceAccountID), - let webFeedID = pasteboardFeed.webFeedID, - let feed = sourceAccount.existingWebFeed(withWebFeedID: webFeedID), + let feedID = pasteboardFeed.feedID, + let feed = sourceAccount.existingFeed(withFeedID: feedID), let destinationContainer = parentNode.representedObject as? Container else { return @@ -391,12 +391,12 @@ private extension SidebarOutlineDataSource { if sameAccount(pasteboardFeed, parentNode) { if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false { - copyWebFeedInAccount(feed, destinationContainer) + copyFeedInAccount(feed, destinationContainer) } else { - moveWebFeedInAccount(feed, sourceContainer, destinationContainer) + moveFeedInAccount(feed, sourceContainer, destinationContainer) } } else { - copyWebFeedBetweenAccounts(feed, destinationContainer) + copyFeedBetweenAccounts(feed, destinationContainer) } } @@ -443,9 +443,9 @@ private extension SidebarOutlineDataSource { destinationAccount.addFolder(folder.name ?? "") { result in switch result { case .success(let destinationFolder): - for feed in folder.topLevelWebFeeds { - if let existingFeed = destinationAccount.existingWebFeed(withURL: feed.url) { - destinationAccount.addWebFeed(existingFeed, to: destinationFolder) { result in + for feed in folder.topLevelFeeds { + if let existingFeed = destinationAccount.existingFeed(withURL: feed.url) { + destinationAccount.addFeed(existingFeed, to: destinationFolder) { result in switch result { case .success: break @@ -454,7 +454,7 @@ private extension SidebarOutlineDataSource { } } } else { - destinationAccount.createWebFeed(url: feed.url, name: feed.nameForDisplay, container: destinationFolder, validateFeed: false) { result in + destinationAccount.createFeed(url: feed.url, name: feed.nameForDisplay, container: destinationFolder, validateFeed: false) { result in switch result { case .success: break @@ -492,29 +492,29 @@ private extension SidebarOutlineDataSource { return true } - func acceptSingleNonLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardWebFeed, _ parentNode: Node, _ index: Int) -> Bool { + func acceptSingleNonLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardFeed, _ parentNode: Node, _ index: Int) -> Bool { guard nodeIsDropTarget(parentNode), index == NSOutlineViewDropOnItemIndex else { return false } // Show the add-feed sheet. if let account = parentNode.representedObject as? Account { - appDelegate.addWebFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: nil) + appDelegate.addFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: nil) } else { let account = parentNode.parent?.representedObject as? Account let folder = parentNode.representedObject as? Folder - appDelegate.addWebFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: folder) + appDelegate.addFeed(draggedFeed.url, name: draggedFeed.editedName ?? draggedFeed.name, account: account, folder: folder) } return true } - func nodeHasChildRepresentingDraggedFeed(_ parentNode: Node, _ draggedFeed: PasteboardWebFeed) -> Bool { + func nodeHasChildRepresentingDraggedFeed(_ parentNode: Node, _ draggedFeed: PasteboardFeed) -> Bool { return nodeHasChildRepresentingAnyDraggedFeed(parentNode, Set([draggedFeed])) } - func nodeRepresentsAnyDraggedFeed(_ node: Node, _ draggedFeeds: Set) -> Bool { - guard let feed = node.representedObject as? WebFeed else { + func nodeRepresentsAnyDraggedFeed(_ node: Node, _ draggedFeeds: Set) -> Bool { + guard let feed = node.representedObject as? Feed else { return false } for draggedFeed in draggedFeeds { @@ -525,8 +525,8 @@ private extension SidebarOutlineDataSource { return false } - func sameAccount(_ pasteboardWebFeed: PasteboardWebFeed, _ parentNode: Node) -> Bool { - if let accountID = pasteboardWebFeed.accountID { + func sameAccount(_ pasteboardFeed: PasteboardFeed, _ parentNode: Node) -> Bool { + if let accountID = pasteboardFeed.accountID { return sameAccount(accountID, parentNode) } return false @@ -553,8 +553,8 @@ private extension SidebarOutlineDataSource { return account } else if let folder = node.representedObject as? Folder { return folder.account - } else if let webFeed = node.representedObject as? WebFeed { - return webFeed.account + } else if let feed = node.representedObject as? Feed { + return feed.account } else { return nil } @@ -565,7 +565,7 @@ private extension SidebarOutlineDataSource { return nodeAccount(node)?.accountID } - func nodeHasChildRepresentingAnyDraggedFeed(_ parentNode: Node, _ draggedFeeds: Set) -> Bool { + func nodeHasChildRepresentingAnyDraggedFeed(_ parentNode: Node, _ draggedFeeds: Set) -> Bool { for node in parentNode.childNodes { if nodeRepresentsAnyDraggedFeed(node, draggedFeeds) { return true @@ -574,11 +574,11 @@ private extension SidebarOutlineDataSource { return false } - func violatesAccountSpecificBehavior(_ dropTargetNode: Node, _ draggedFeed: PasteboardWebFeed) -> Bool { + func violatesAccountSpecificBehavior(_ dropTargetNode: Node, _ draggedFeed: PasteboardFeed) -> Bool { return violatesAccountSpecificBehavior(dropTargetNode, Set([draggedFeed])) } - func violatesAccountSpecificBehavior(_ dropTargetNode: Node, _ draggedFeeds: Set) -> Bool { + func violatesAccountSpecificBehavior(_ dropTargetNode: Node, _ draggedFeeds: Set) -> Bool { if violatesDisallowFeedInRootFolder(dropTargetNode) { return true } @@ -606,7 +606,7 @@ private extension SidebarOutlineDataSource { return false } - func violatesDisallowFeedCopyInRootFolder(_ dropTargetNode: Node, _ draggedFeeds: Set) -> Bool { + func violatesDisallowFeedCopyInRootFolder(_ dropTargetNode: Node, _ draggedFeeds: Set) -> Bool { guard let dropTargetAccount = nodeAccount(dropTargetNode), dropTargetAccount.behaviors.contains(.disallowFeedCopyInRootFolder) else { return false } @@ -624,7 +624,7 @@ private extension SidebarOutlineDataSource { return false } - func violatesDisallowFeedInMultipleFolders(_ dropTargetNode: Node, _ draggedFeeds: Set) -> Bool { + func violatesDisallowFeedInMultipleFolders(_ dropTargetNode: Node, _ draggedFeeds: Set) -> Bool { guard let dropTargetAccount = nodeAccount(dropTargetNode), dropTargetAccount.behaviors.contains(.disallowFeedInMultipleFolders) else { return false } @@ -635,7 +635,7 @@ private extension SidebarOutlineDataSource { return true } } else { - if dropTargetAccount.hasWebFeed(withURL: draggedFeed.url) { + if dropTargetAccount.hasFeed(withURL: draggedFeed.url) { return true } } @@ -644,7 +644,7 @@ private extension SidebarOutlineDataSource { return false } - func indexWhereDraggedFeedWouldAppear(_ parentNode: Node, _ draggedFeed: PasteboardWebFeed) -> Int { + func indexWhereDraggedFeedWouldAppear(_ parentNode: Node, _ draggedFeed: PasteboardFeed) -> Int { let draggedFeedWrapper = PasteboardFeedObjectWrapper(pasteboardFeed: draggedFeed) let draggedFeedNode = Node(representedObject: draggedFeedWrapper, parent: nil) let nodes = parentNode.childNodes + [draggedFeedNode] @@ -673,9 +673,9 @@ final class PasteboardFeedObjectWrapper: DisplayNameProvider { var nameForDisplay: String { return pasteboardFeed.editedName ?? pasteboardFeed.name ?? "" } - let pasteboardFeed: PasteboardWebFeed + let pasteboardFeed: PasteboardFeed - init(pasteboardFeed: PasteboardWebFeed) { + init(pasteboardFeed: PasteboardFeed) { self.pasteboardFeed = pasteboardFeed } } diff --git a/Mac/MainWindow/Sidebar/SidebarViewController+ContextualMenus.swift b/Mac/MainWindow/Sidebar/SidebarViewController+ContextualMenus.swift index 4bff3aca6..7655c7759 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController+ContextualMenus.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController+ContextualMenus.swift @@ -31,8 +31,8 @@ extension SidebarViewController { let object = objects.first! switch object { - case is WebFeed: - return menuForWebFeed(object as! WebFeed) + case is Feed: + return menuForFeed(object as! Feed) case is Folder: return menuForFolder(object as! Folder) case is PseudoFeed: @@ -93,7 +93,7 @@ extension SidebarViewController { @objc func renameFromContextualMenu(_ sender: Any?) { - guard let window = view.window, let menuItem = sender as? NSMenuItem, let object = menuItem.representedObject as? DisplayNameProvider, object is WebFeed || object is Folder else { + guard let window = view.window, let menuItem = sender as? NSMenuItem, let object = menuItem.representedObject as? DisplayNameProvider, object is Feed || object is Folder else { return } @@ -106,7 +106,7 @@ extension SidebarViewController { @objc func toggleNotificationsFromContextMenu(_ sender: Any?) { guard let item = sender as? NSMenuItem, - let feed = item.representedObject as? WebFeed else { + let feed = item.representedObject as? Feed else { return } UNUserNotificationCenter.current().getNotificationSettings { (settings) in @@ -137,7 +137,7 @@ extension SidebarViewController { @objc func toggleArticleExtractorFromContextMenu(_ sender: Any?) { guard let item = sender as? NSMenuItem, - let feed = item.representedObject as? WebFeed else { + let feed = item.representedObject as? Feed else { return } if feed.isArticleExtractorAlwaysOn == nil { feed.isArticleExtractorAlwaysOn = false } @@ -170,7 +170,7 @@ extension SidebarViewController: RenameWindowControllerDelegate { func renameWindowController(_ windowController: RenameWindowController, didRenameObject object: Any, withNewName name: String) { - if let feed = object as? WebFeed { + if let feed = object as? Feed { feed.rename(to: name) { result in switch result { case .success: @@ -200,40 +200,40 @@ private extension SidebarViewController { let menu = NSMenu(title: "") - menu.addItem(withTitle: NSLocalizedString("New Feed", comment: "Command"), action: #selector(AppDelegate.showAddWebFeedWindow(_:)), keyEquivalent: "") + menu.addItem(withTitle: NSLocalizedString("New Feed", comment: "Command"), action: #selector(AppDelegate.showAddFeedWindow(_:)), keyEquivalent: "") menu.addItem(withTitle: NSLocalizedString("New Folder", comment: "Command"), action: #selector(AppDelegate.showAddFolderWindow(_:)), keyEquivalent: "") return menu } - func menuForWebFeed(_ webFeed: WebFeed) -> NSMenu? { + func menuForFeed(_ feed: Feed) -> NSMenu? { let menu = NSMenu(title: "") - if webFeed.unreadCount > 0 { - menu.addItem(markAllReadMenuItem([webFeed])) + if feed.unreadCount > 0 { + menu.addItem(markAllReadMenuItem([feed])) menu.addItem(NSMenuItem.separator()) } - if let homePageURL = webFeed.homePageURL, let _ = URL(string: homePageURL) { + if let homePageURL = feed.homePageURL, let _ = URL(string: homePageURL) { let item = menuItem(NSLocalizedString("Open Home Page", comment: "Command"), #selector(openHomePageFromContextualMenu(_:)), homePageURL, image: AppAssets.openInBrowserImage) menu.addItem(item) menu.addItem(NSMenuItem.separator()) } - let copyFeedURLItem = menuItem(NSLocalizedString("Copy Feed URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), webFeed.url, image: AppAssets.copyImage) + let copyFeedURLItem = menuItem(NSLocalizedString("Copy Feed URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), feed.url, image: AppAssets.copyImage) menu.addItem(copyFeedURLItem) - if let homePageURL = webFeed.homePageURL { + if let homePageURL = feed.homePageURL { let item = menuItem(NSLocalizedString("Copy Home Page URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), homePageURL, image: AppAssets.copyImage) menu.addItem(item) } menu.addItem(NSMenuItem.separator()) - let notificationText = webFeed.notificationDisplayName.capitalized + let notificationText = feed.notificationDisplayName.capitalized - let notificationMenuItem = menuItem(notificationText, #selector(toggleNotificationsFromContextMenu(_:)), webFeed, image: AppAssets.notificationImage) - if webFeed.isNotifyAboutNewArticles == nil || webFeed.isNotifyAboutNewArticles! == false { + let notificationMenuItem = menuItem(notificationText, #selector(toggleNotificationsFromContextMenu(_:)), feed, image: AppAssets.notificationImage) + if feed.isNotifyAboutNewArticles == nil || feed.isNotifyAboutNewArticles! == false { notificationMenuItem.state = .off } else { notificationMenuItem.state = .on @@ -241,9 +241,9 @@ private extension SidebarViewController { menu.addItem(notificationMenuItem) let articleExtractorText = NSLocalizedString("Always Use Reader View", comment: "Always Use Reader View") - let articleExtractorMenuItem = menuItem(articleExtractorText, #selector(toggleArticleExtractorFromContextMenu(_:)), webFeed, image: AppAssets.articleExtractorOff) + let articleExtractorMenuItem = menuItem(articleExtractorText, #selector(toggleArticleExtractorFromContextMenu(_:)), feed, image: AppAssets.articleExtractorOff) - if webFeed.isArticleExtractorAlwaysOn == nil || webFeed.isArticleExtractorAlwaysOn! == false { + if feed.isArticleExtractorAlwaysOn == nil || feed.isArticleExtractorAlwaysOn! == false { articleExtractorMenuItem.state = .off } else { articleExtractorMenuItem.state = .on @@ -252,8 +252,8 @@ private extension SidebarViewController { menu.addItem(NSMenuItem.separator()) - menu.addItem(renameMenuItem(webFeed)) - menu.addItem(deleteMenuItem([webFeed])) + menu.addItem(renameMenuItem(feed)) + menu.addItem(deleteMenuItem([feed])) return menu } @@ -338,7 +338,7 @@ private extension SidebarViewController { func objectIsFeedOrFolder(_ object: Any) -> Bool { - return object is WebFeed || object is Folder + return object is Feed || object is Folder } func menuItem(_ title: String, _ action: Selector, _ representedObject: Any, image: RSImage?) -> NSMenuItem { diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 25d8a0360..cf4f6779e 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -37,7 +37,7 @@ protocol SidebarDelegate: AnyObject { } private let rebuildTreeAndRestoreSelectionQueue = CoalescingQueue(name: "Rebuild Tree Queue", interval: 1.0) - let treeControllerDelegate = WebFeedTreeControllerDelegate() + let treeControllerDelegate = SidebarTreeControllerDelegate() lazy var treeController: TreeController = { return TreeController(delegate: treeControllerDelegate) }() @@ -72,7 +72,7 @@ protocol SidebarDelegate: AnyObject { outlineView.dataSource = dataSource outlineView.doubleAction = #selector(doubleClickedSidebar(_:)) outlineView.setDraggingSourceOperationMask([.move, .copy], forLocal: true) - outlineView.registerForDraggedTypes([WebFeedPasteboardWriter.webFeedUTIInternalType, WebFeedPasteboardWriter.webFeedUTIType, .URL, .string]) + outlineView.registerForDraggedTypes([FeedPasteboardWriter.feedUTIInternalType, FeedPasteboardWriter.feedUTIType, .URL, .string]) NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidInitialize(_:)), name: .UnreadCountDidInitialize, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) @@ -83,8 +83,8 @@ protocol SidebarDelegate: AnyObject { NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil) 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: .feedIconDidBecomeAvailable, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), 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) @@ -216,7 +216,7 @@ protocol SidebarDelegate: AnyObject { } @objc func userDidAddFeed(_ notification: Notification) { - guard let feed = notification.userInfo?[UserInfoKey.webFeed] else { + guard let feed = notification.userInfo?[UserInfoKey.feed] else { return } revealAndSelectRepresentedObject(feed as AnyObject) @@ -226,17 +226,17 @@ protocol SidebarDelegate: AnyObject { applyToAvailableCells(configureFavicon) } - @objc func webFeedIconDidBecomeAvailable(_ note: Notification) { - guard let webFeed = note.userInfo?[UserInfoKey.webFeed] as? WebFeed else { return } - configureCellsForRepresentedObject(webFeed) + @objc func feedIconDidBecomeAvailable(_ note: Notification) { + guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else { return } + configureCellsForRepresentedObject(feed) } - @objc func webFeedSettingDidChange(_ note: Notification) { - guard let webFeed = note.object as? WebFeed, let key = note.userInfo?[WebFeed.WebFeedSettingUserInfoKey] as? String else { + @objc func feedSettingDidChange(_ note: Notification) { + guard let feed = note.object as? Feed, let key = note.userInfo?[Feed.SettingUserInfoKey] as? String else { return } - if key == WebFeed.WebFeedSettingKey.homePageURL || key == WebFeed.WebFeedSettingKey.faviconURL { - configureCellsForRepresentedObject(webFeed) + if key == Feed.SettingKey.homePageURL || key == Feed.SettingKey.faviconURL { + configureCellsForRepresentedObject(feed) } } @@ -288,7 +288,7 @@ protocol SidebarDelegate: AnyObject { guard outlineView.clickedRow == outlineView.selectedRow else { return } - if AppDefaults.shared.feedDoubleClickMarkAsRead, let articles = try? singleSelectedWebFeed?.fetchUnreadArticles() { + if AppDefaults.shared.feedDoubleClickMarkAsRead, let articles = try? singleSelectedFeed?.fetchUnreadArticles() { if let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: Array(articles), markingRead: true, undoManager: undoManager) { runCommand(markReadCommand) } @@ -297,7 +297,7 @@ protocol SidebarDelegate: AnyObject { } @IBAction func openInBrowser(_ sender: Any?) { - guard let feed = singleSelectedWebFeed, let homePageURL = feed.homePageURL else { + guard let feed = singleSelectedFeed, let homePageURL = feed.homePageURL else { return } Browser.open(homePageURL, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false) @@ -305,7 +305,7 @@ protocol SidebarDelegate: AnyObject { @objc func openInAppBrowser(_ sender: Any?) { // There is no In-App Browser for mac - so we use safari - guard let feed = singleSelectedWebFeed, let homePageURL = feed.homePageURL else { + guard let feed = singleSelectedFeed, let homePageURL = feed.homePageURL else { return } Browser.open(homePageURL, invertPreference: NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false) @@ -485,8 +485,8 @@ protocol SidebarDelegate: AnyObject { if isReadFiltered, let sidebarItemID = sidebarItem.sidebarItemID { self.treeControllerDelegate.addFilterException(sidebarItemID) - if let webFeed = sidebarItem as? WebFeed, let account = webFeed.account { - let parentFolder = account.sortedFolders?.first(where: { $0.objectIsChild(webFeed) }) + if let feed = sidebarItem as? Feed, let account = feed.account { + let parentFolder = account.sortedFolders?.first(where: { $0.objectIsChild(feed) }) if let parentFolderSidebarItemID = parentFolder?.sidebarItemID { self.treeControllerDelegate.addFilterException(parentFolderSidebarItemID) } @@ -558,11 +558,11 @@ private extension SidebarViewController { return selectedNodes.first! } - var singleSelectedWebFeed: WebFeed? { + var singleSelectedFeed: Feed? { guard let node = singleSelectedNode else { return nil } - return node.representedObject as? WebFeed + return node.representedObject as? Feed } func addAllSelectedToFilterExceptions() { @@ -577,10 +577,10 @@ private extension SidebarViewController { if folderFeed.account?.existingFolder(withID: folderFeed.folderID) != nil { treeControllerDelegate.addFilterException(sidebarItemID) } - } else if let webFeed = sidebarItem as? WebFeed { - if webFeed.account?.existingWebFeed(withWebFeedID: webFeed.webFeedID) != nil { + } else if let feed = sidebarItem as? Feed { + if feed.account?.existingFeed(withFeedID: feed.feedID) != nil { treeControllerDelegate.addFilterException(sidebarItemID) - addParentFolderToFilterExceptions(webFeed) + addParentFolderToFilterExceptions(feed) } } } @@ -775,10 +775,10 @@ private extension SidebarViewController { } func findFeedNode(_ userInfo: [AnyHashable : Any]?, beginningAt startingNode: Node) -> Node? { - guard let webFeedID = userInfo?[ArticlePathKey.webFeedID] as? String else { + guard let feedID = userInfo?[ArticlePathKey.feedID] as? String else { return nil } - if let node = startingNode.descendantNode(where: { ($0.representedObject as? WebFeed)?.webFeedID == webFeedID }) { + if let node = startingNode.descendantNode(where: { ($0.representedObject as? Feed)?.feedID == feedID }) { return node } return nil @@ -805,7 +805,7 @@ private extension SidebarViewController { } func imageFor(_ node: Node) -> IconImage? { - if let feed = node.representedObject as? WebFeed, let feedIcon = IconImageCache.shared.imageForFeed(feed) { + if let feed = node.representedObject as? Feed, let feedIcon = IconImageCache.shared.imageForFeed(feed) { return feedIcon } if let smallIconProvider = node.representedObject as? SmallIconProvider { @@ -895,7 +895,7 @@ private extension Node { if representedObject === object { return true } - if let feed1 = object as? WebFeed, let feed2 = representedObject as? WebFeed { + if let feed1 = object as? Feed, let feed2 = representedObject as? Feed { return feed1 == feed2 } return false diff --git a/Mac/MainWindow/Timeline/ArticlePasteboardWriter.swift b/Mac/MainWindow/Timeline/ArticlePasteboardWriter.swift index 29be01571..52aa89b2c 100644 --- a/Mac/MainWindow/Timeline/ArticlePasteboardWriter.swift +++ b/Mac/MainWindow/Timeline/ArticlePasteboardWriter.swift @@ -96,7 +96,7 @@ private extension ArticlePasteboardWriter { s += "Date: \(article.logicalDatePublished)\n\n" - if let feed = article.webFeed { + if let feed = article.feed { s += "Feed: \(feed.nameForDisplay)\n" if let homePageURL = feed.homePageURL { s += "Home page: \(homePageURL)\n" @@ -111,7 +111,7 @@ private extension ArticlePasteboardWriter { static let articleID = "articleID" // database ID, unique per account static let uniqueID = "uniqueID" // unique ID, unique per feed (guid, or possibly calculated) static let feedURL = "feedURL" - static let webFeedID = "webFeedID" // may differ from feedURL if coming from a syncing system + static let feedID = "feedID" // may differ from feedURL if coming from a syncing system static let title = "title" static let contentHTML = "contentHTML" static let contentText = "contentText" @@ -143,11 +143,11 @@ private extension ArticlePasteboardWriter { d[Key.articleID] = article.articleID d[Key.uniqueID] = article.uniqueID - if let feed = article.webFeed { + if let feed = article.feed { d[Key.feedURL] = feed.url } - d[Key.webFeedID] = article.webFeedID + d[Key.feedID] = article.feedID d[Key.title] = article.title ?? nil d[Key.contentHTML] = article.contentHTML ?? nil d[Key.contentText] = article.contentText ?? nil diff --git a/Mac/MainWindow/Timeline/TimelineContainerViewController.swift b/Mac/MainWindow/Timeline/TimelineContainerViewController.swift index 9a173b8a3..78abb4aff 100644 --- a/Mac/MainWindow/Timeline/TimelineContainerViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineContainerViewController.swift @@ -12,7 +12,7 @@ import Articles protocol TimelineContainerViewControllerDelegate: AnyObject { func timelineSelectionDidChange(_: TimelineContainerViewController, articles: [Article]?, mode: TimelineSourceMode) - func timelineRequestedWebFeedSelection(_: TimelineContainerViewController, webFeed: WebFeed) + func timelineRequestedFeedSelection(_: TimelineContainerViewController, feed: Feed) func timelineInvalidatedRestorationState(_: TimelineContainerViewController) } @@ -153,8 +153,8 @@ extension TimelineContainerViewController: TimelineDelegate { delegate?.timelineSelectionDidChange(self, articles: selectedArticles, mode: mode(for: timelineViewController)) } - func timelineRequestedWebFeedSelection(_: TimelineViewController, webFeed: WebFeed) { - delegate?.timelineRequestedWebFeedSelection(self, webFeed: webFeed) + func timelineRequestedFeedSelection(_: TimelineViewController, feed: Feed) { + delegate?.timelineRequestedFeedSelection(self, feed: feed) } func timelineInvalidatedRestorationState(_: TimelineViewController) { diff --git a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift index 85aafb084..2d1af736d 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift @@ -65,15 +65,15 @@ extension TimelineViewController { } @objc func selectFeedInSidebarFromContextualMenu(_ sender: Any?) { - guard let menuItem = sender as? NSMenuItem, let webFeed = menuItem.representedObject as? WebFeed else { + guard let menuItem = sender as? NSMenuItem, let feed = menuItem.representedObject as? Feed else { return } - delegate?.timelineRequestedWebFeedSelection(self, webFeed: webFeed) + delegate?.timelineRequestedFeedSelection(self, feed: feed) } @objc func markAllInFeedAsRead(_ sender: Any?) { guard let menuItem = sender as? NSMenuItem, - let feed = menuItem.representedObject as? WebFeed else { + let feed = menuItem.representedObject as? Feed else { return } @@ -171,8 +171,8 @@ private extension TimelineViewController { menu.addSeparatorIfNeeded() - if articles.count == 1, let feed = articles.first!.webFeed { - if !(representedObjects?.contains(where: { $0 as? WebFeed == feed }) ?? false) { + if articles.count == 1, let feed = articles.first!.feed { + if !(representedObjects?.contains(where: { $0 as? Feed == feed }) ?? false) { menu.addItem(selectFeedInSidebarMenuItem(feed)) } if let markAllMenuItem = markAllAsReadMenuItem(feed) { @@ -256,13 +256,13 @@ private extension TimelineViewController { return menuItem(NSLocalizedString("Mark Below as Read", comment: "Command"), #selector(markBelowArticlesReadFromContextualMenu(_:)), articles, image: AppAssets.markBelowAsReadImage) } - func selectFeedInSidebarMenuItem(_ feed: WebFeed) -> NSMenuItem { + func selectFeedInSidebarMenuItem(_ feed: Feed) -> NSMenuItem { let localizedMenuText = NSLocalizedString("Select “%@” in Sidebar", comment: "Command") let formattedMenuText = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) return menuItem(formattedMenuText as String, #selector(selectFeedInSidebarFromContextualMenu(_:)), feed, image: nil) } - func markAllAsReadMenuItem(_ feed: WebFeed) -> NSMenuItem? { + func markAllAsReadMenuItem(_ feed: Feed) -> NSMenuItem? { guard feed.unreadCount > 0 else { return nil } diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index eee3f8d55..213d6c74b 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -14,7 +14,7 @@ import os.log protocol TimelineDelegate: AnyObject { func timelineSelectionDidChange(_: TimelineViewController, selectedArticles: [Article]?) - func timelineRequestedWebFeedSelection(_: TimelineViewController, webFeed: WebFeed) + func timelineRequestedFeedSelection(_: TimelineViewController, feed: Feed) func timelineInvalidatedRestorationState(_: TimelineViewController) } @@ -129,7 +129,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr return } - if let representedObjects = representedObjects, representedObjects.count == 1 && representedObjects.first is WebFeed { + if let representedObjects = representedObjects, representedObjects.count == 1 && representedObjects.first is Feed { showFeedNames = { for article in articles { if !article.byline().isEmpty { @@ -232,7 +232,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr if !didRegisterForNotifications { NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(webFeedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(accountDidDownloadArticles(_:)), name: .AccountDidDownloadArticles, object: nil) @@ -628,15 +628,15 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr updateUnreadCount() } - @objc func webFeedIconDidBecomeAvailable(_ note: Notification) { - guard showIcons, let feed = note.userInfo?[UserInfoKey.webFeed] as? WebFeed else { + @objc func feedIconDidBecomeAvailable(_ note: Notification) { + guard showIcons, let feed = note.userInfo?[UserInfoKey.feed] as? Feed else { return } let indexesToReload = tableView.indexesOfAvailableRowsPassingTest { (row) -> Bool in guard let article = articles.articleAtRow(row) else { return false } - return feed == article.webFeed + return feed == article.feed } if let indexesToReload = indexesToReload { reloadCells(for: indexesToReload) @@ -671,11 +671,11 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr } @objc func accountDidDownloadArticles(_ note: Notification) { - guard let feeds = note.userInfo?[Account.UserInfoKey.webFeeds] as? Set else { + guard let feeds = note.userInfo?[Account.UserInfoKey.feeds] as? Set else { return } - let shouldFetchAndMergeArticles = representedObjectsContainsAnyWebFeed(feeds) || representedObjectsContainsAnyPseudoFeed() + let shouldFetchAndMergeArticles = representedObjectsContainsAnyFeed(feeds) || representedObjectsContainsAnyPseudoFeed() if shouldFetchAndMergeArticles { queueFetchAndMergeArticles() } @@ -761,8 +761,8 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr let longTitle = "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?" let prototypeID = "prototype" let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, dateArrived: Date()) - let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, webFeedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, markdown: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, datePublished: nil, dateModified: nil, authors: nil, status: status) - + let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, feedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, markdown: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, datePublished: nil, dateModified: nil, authors: nil, status: status) + let prototypeCellData = TimelineCellData(article: prototypeArticle, showFeedName: .feed, feedName: "Prototype Feed Name", byline: nil, iconImage: nil, showIcon: false) let height = TimelineCellLayout.height(for: 100, cellData: prototypeCellData, appearance: cellAppearance) return height @@ -922,7 +922,7 @@ extension TimelineViewController: NSTableViewDelegate { private func configureTimelineCell(_ cell: TimelineTableCellView, article: Article) { cell.objectValue = article let iconImage = article.iconImage() - cell.cellData = TimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.webFeed?.nameForDisplay, byline: article.byline(), iconImage: iconImage, showIcon: showIcons) + cell.cellData = TimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, byline: article.byline(), iconImage: iconImage, showIcon: showIcons) } private func iconFor(_ article: Article) -> IconImage? { @@ -1269,23 +1269,23 @@ private extension TimelineViewController { return representedObjects?.contains(where: { $0 is Folder }) ?? false } - func representedObjectsContainsAnyWebFeed(_ webFeeds: Set) -> Bool { + func representedObjectsContainsAnyFeed(_ feeds: Set) -> Bool { // Return true if there’s a match or if a folder contains (recursively) one of feeds guard let representedObjects = representedObjects else { return false } for representedObject in representedObjects { - if let feed = representedObject as? WebFeed { - for oneFeed in webFeeds { - if feed.webFeedID == oneFeed.webFeedID || feed.url == oneFeed.url { + if let feed = representedObject as? Feed { + for oneFeed in feeds { + if feed.feedID == oneFeed.feedID || feed.url == oneFeed.url { return true } } } else if let folder = representedObject as? Folder { - for oneFeed in webFeeds { - if folder.hasWebFeed(with: oneFeed.webFeedID) || folder.hasWebFeed(withURL: oneFeed.url) { + for oneFeed in feeds { + if folder.hasFeed(with: oneFeed.feedID) || folder.hasFeed(withURL: oneFeed.url) { return true } } diff --git a/Mac/Resources/NetNewsWire.sdef b/Mac/Resources/NetNewsWire.sdef index d732ad00e..bd5706e59 100644 --- a/Mac/Resources/NetNewsWire.sdef +++ b/Mac/Resources/NetNewsWire.sdef @@ -73,9 +73,9 @@ - - - + + + @@ -105,30 +105,30 @@ - - - - + + + + - - - + + + - + - + - - - + + + @@ -189,9 +189,9 @@ - - - + + + @@ -245,7 +245,7 @@ - + diff --git a/Mac/Scriptability/Account+Scriptability.swift b/Mac/Scriptability/Account+Scriptability.swift index b1a4a0ed2..8aedef6f7 100644 --- a/Mac/Scriptability/Account+Scriptability.swift +++ b/Mac/Scriptability/Account+Scriptability.swift @@ -73,7 +73,7 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec account.removeFolder(scriptableFolder.folder) { result in } } - } else if let scriptableFeed = element as? ScriptableWebFeed { + } else if let scriptableFeed = element as? ScriptableFeed { BatchUpdate.shared.perform { var container: Container? = nil if let scriptableFolder = scriptableFeed.container as? ScriptableFolder { @@ -81,7 +81,7 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec } else { container = account } - account.removeWebFeed(scriptableFeed.webFeed, from: container!) { result in + account.removeFeed(scriptableFeed.feed, from: container!) { result in } } } @@ -94,34 +94,34 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec // MARK: --- Scriptable elements --- - @objc(webFeeds) - var webFeeds:NSArray { - return account.topLevelWebFeeds.map { ScriptableWebFeed($0, container:self) } as NSArray + @objc(feeds) + var feeds:NSArray { + return account.topLevelFeeds.map { ScriptableFeed($0, container:self) } as NSArray } - @objc(countOfWebFeeds) - func countOfWebFeeds() -> Int { - return account.topLevelWebFeeds.count + @objc(countOfFeeds) + func countOfFeeds() -> Int { + return account.topLevelFeeds.count } - @objc(objectInWebFeedsAtIndex:) - func objectInWebFeedsAtIndex(_ index: Int) -> ScriptableWebFeed? { - let feeds = Array(account.topLevelWebFeeds) + @objc(objectInFeedsAtIndex:) + func objectInFeedsAtIndex(_ index: Int) -> ScriptableFeed? { + let feeds = Array(account.topLevelFeeds) guard index >= 0 && index < feeds.count else { return nil } - return ScriptableWebFeed(feeds[index], container: self) + return ScriptableFeed(feeds[index], container: self) } - @objc(valueInWebFeedsWithUniqueID:) - func valueInWebFeeds(withUniqueID id:String) -> ScriptableWebFeed? { - guard let feed = account.existingWebFeed(withWebFeedID: id) else { return nil } - return ScriptableWebFeed(feed, container:self) + @objc(valueInFeedsWithUniqueID:) + func valueInFeeds(withUniqueID id:String) -> ScriptableFeed? { + guard let feed = account.existingFeed(withFeedID: id) else { return nil } + return ScriptableFeed(feed, container:self) } - @objc(valueInWebFeedsWithName:) - func valueInWebFeeds(withName name:String) -> ScriptableWebFeed? { - let feeds = Array(account.flattenedWebFeeds()) + @objc(valueInFeedsWithName:) + func valueInFeeds(withName name:String) -> ScriptableFeed? { + let feeds = Array(account.flattenedFeeds()) guard let feed = feeds.first(where:{$0.name == name}) else { return nil } - return ScriptableWebFeed(feed, container:self) + return ScriptableFeed(feed, container:self) } @objc(folders) @@ -155,38 +155,38 @@ final class ScriptableAccount: NSObject, UniqueIdScriptingObject, ScriptingObjec // MARK: --- Scriptable properties --- - @objc(allWebFeeds) - var allWebFeeds: NSArray { - let allFeeds = account.flattenedWebFeeds() - let scriptableWebFeeds = allFeeds.map { webFeed in - return ScriptableWebFeed(webFeed, container: self) + @objc(allFeeds) + var allFeeds: NSArray { + let allFeeds = account.flattenedFeeds() + let scriptableFeeds = allFeeds.map { feed in + return ScriptableFeed(feed, container: self) } - return scriptableWebFeeds as NSArray + return scriptableFeeds as NSArray } - @objc(countOfAllWebFeeds) - func countOfAllWebFeeds() -> Int { - return account.flattenedWebFeeds().count + @objc(countOfAllFeeds) + func countOfAllFeeds() -> Int { + return account.flattenedFeeds().count } - @objc(objectInAllWebFeedsAtIndex:) - func objectInAllWebFeedsAtIndex(_ index: Int) -> ScriptableWebFeed? { - let allFeeds = Array(account.flattenedWebFeeds()) + @objc(objectInAllFeedsAtIndex:) + func objectInAllFeedsAtIndex(_ index: Int) -> ScriptableFeed? { + let allFeeds = Array(account.flattenedFeeds()) guard index >= 0 && index < allFeeds.count else { return nil } - return ScriptableWebFeed(allFeeds[index], container: self) + return ScriptableFeed(allFeeds[index], container: self) } - @objc(valueInAllWebFeedsWithUniqueID:) - func valueInAllWebFeeds(withUniqueID id:String) -> ScriptableWebFeed? { - guard let feed = account.existingWebFeed(withWebFeedID: id) else { return nil } - return ScriptableWebFeed(feed, container:self) + @objc(valueInAllFeedsWithUniqueID:) + func valueInAllFeeds(withUniqueID id:String) -> ScriptableFeed? { + guard let feed = account.existingFeed(withFeedID: id) else { return nil } + return ScriptableFeed(feed, container:self) } - @objc(valueInAllWebFeedsWithName:) - func valueInAllWebFeeds(withName name:String) -> ScriptableWebFeed? { - let feeds = Array(account.flattenedWebFeeds()) + @objc(valueInAllFeedsWithName:) + func valueInAllFeeds(withName name:String) -> ScriptableFeed? { + let feeds = Array(account.flattenedFeeds()) guard let feed = feeds.first(where:{$0.name == name}) else { return nil } - return ScriptableWebFeed(feed, container:self) + return ScriptableFeed(feed, container:self) } @objc(opmlRepresentation) diff --git a/Mac/Scriptability/AppDelegate+Scriptability.swift b/Mac/Scriptability/AppDelegate+Scriptability.swift index ace5db934..39a13c703 100644 --- a/Mac/Scriptability/AppDelegate+Scriptability.swift +++ b/Mac/Scriptability/AppDelegate+Scriptability.swift @@ -86,7 +86,7 @@ extension AppDelegate : AppDelegateAppleEvents { DispatchQueue.main.async { - self.addWebFeed(normalizedURLString) + self.addFeed(normalizedURLString) } } } @@ -94,8 +94,8 @@ extension AppDelegate : AppDelegateAppleEvents { final class NetNewsWireCreateElementCommand : NSCreateCommand { override func performDefaultImplementation() -> Any? { let classDescription = self.createClassDescription - if (classDescription.className == "webFeed") { - return ScriptableWebFeed.handleCreateElement(command:self) + if (classDescription.className == "feed") { + return ScriptableFeed.handleCreateElement(command:self) } else if (classDescription.className == "folder") { return ScriptableFolder.handleCreateElement(command:self) } diff --git a/Mac/Scriptability/Article+Scriptability.swift b/Mac/Scriptability/Article+Scriptability.swift index aa1c516cd..e3a34e46f 100644 --- a/Mac/Scriptability/Article+Scriptability.swift +++ b/Mac/Scriptability/Article+Scriptability.swift @@ -142,8 +142,8 @@ final class ScriptableArticle: NSObject, UniqueIdScriptingObject, ScriptingObjec } @objc(feed) - var feed: ScriptableWebFeed? { - guard let parentFeed = self.article.webFeed else { return nil } - return ScriptableWebFeed.scriptableWebFeed(for: parentFeed) + var feed: ScriptableFeed? { + guard let parentFeed = self.article.feed else { return nil } + return ScriptableFeed.scriptableFeed(for: parentFeed) } } diff --git a/Mac/Scriptability/WebFeed+Scriptability.swift b/Mac/Scriptability/Feed+Scriptability.swift similarity index 79% rename from Mac/Scriptability/WebFeed+Scriptability.swift rename to Mac/Scriptability/Feed+Scriptability.swift index d0792ff75..659f04446 100644 --- a/Mac/Scriptability/WebFeed+Scriptability.swift +++ b/Mac/Scriptability/Feed+Scriptability.swift @@ -11,14 +11,14 @@ import RSParser import Account import Articles -@objc(ScriptableWebFeed) -final class ScriptableWebFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContainer { +@objc(ScriptableFeed) +final class ScriptableFeed: NSObject, UniqueIdScriptingObject, ScriptingObjectContainer { - let webFeed:WebFeed + let feed:Feed let container:ScriptingObjectContainer - init (_ webFeed:WebFeed, container:ScriptingObjectContainer) { - self.webFeed = webFeed + init (_ feed:Feed, container:ScriptingObjectContainer) { + self.feed = feed self.container = container } @@ -36,7 +36,7 @@ final class ScriptableWebFeed: NSObject, UniqueIdScriptingObject, ScriptingObjec // MARK: --- ScriptingObject protocol --- var scriptingKey: String { - return "webFeeds" + return "feeds" } // MARK: --- UniqueIdScriptingObject protocol --- @@ -45,7 +45,7 @@ final class ScriptableWebFeed: NSObject, UniqueIdScriptingObject, ScriptingObjec // but in either case it seems like the accountID would be used as the keydata, so I chose ID @objc(uniqueId) var scriptingUniqueId:Any { - return webFeed.webFeedID + return feed.feedID } // MARK: --- ScriptingObjectContainer protocol --- @@ -71,21 +71,21 @@ final class ScriptableWebFeed: NSObject, UniqueIdScriptingObject, ScriptingObjec return url } - class func scriptableFeed(_ feed:WebFeed, account:Account, folder:Folder?) -> ScriptableWebFeed { + class func scriptableFeed(_ feed:Feed, account:Account, folder:Folder?) -> ScriptableFeed { let scriptableAccount = ScriptableAccount(account) if let folder = folder { let scriptableFolder = ScriptableFolder(folder, container:scriptableAccount) - return ScriptableWebFeed(feed, container:scriptableFolder) + return ScriptableFeed(feed, container:scriptableFolder) } else { - return ScriptableWebFeed(feed, container:scriptableAccount) + return ScriptableFeed(feed, container:scriptableAccount) } } - class func scriptableWebFeed(for feed: WebFeed) -> ScriptableWebFeed? { + class func scriptableFeed(for feed: Feed) -> ScriptableFeed? { guard let account = feed.account else { return nil } // Find the proper container hierarchy - let containers = account.existingContainers(withWebFeed: feed) + let containers = account.existingContainers(withFeed: feed) var folder: Folder? = nil // Check if feed is in a folder @@ -106,7 +106,7 @@ final class ScriptableWebFeed: NSObject, UniqueIdScriptingObject, ScriptingObjec let (account, folder) = command.accountAndFolderForNewChild() guard let url = self.urlForNewFeed(arguments:arguments) else {return nil} - if let existingFeed = account.existingWebFeed(withURL:url) { + if let existingFeed = account.existingFeed(withURL:url) { return scriptableFeed(existingFeed, account:account, folder:folder).objectSpecifier } @@ -120,10 +120,10 @@ final class ScriptableWebFeed: NSObject, UniqueIdScriptingObject, ScriptingObjec // suspendExecution(). When we get the callback, we supply the event result and call resumeExecution(). command.suspendExecution() - account.createWebFeed(url: url, name: titleFromArgs, container: container, validateFeed: true) { result in + account.createFeed(url: url, name: titleFromArgs, container: container, validateFeed: true) { result in switch result { case .success(let feed): - NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.webFeed: feed]) + NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed]) let scriptableFeed = self.scriptableFeed(feed, account:account, folder:folder) command.resumeExecution(withResult:scriptableFeed.objectSpecifier) case .failure: @@ -139,51 +139,51 @@ final class ScriptableWebFeed: NSObject, UniqueIdScriptingObject, ScriptingObjec @objc(url) var url:String { - return self.webFeed.url + return self.feed.url } @objc(name) var name:String { - return self.webFeed.name ?? "" + return self.feed.name ?? "" } @objc(homePageURL) var homePageURL:String { - return self.webFeed.homePageURL ?? "" + return self.feed.homePageURL ?? "" } @objc(iconURL) var iconURL:String { - return self.webFeed.iconURL ?? "" + return self.feed.iconURL ?? "" } @objc(faviconURL) var faviconURL:String { - return self.webFeed.faviconURL ?? "" + return self.feed.faviconURL ?? "" } @objc(opmlRepresentation) var opmlRepresentation:String { - return self.webFeed.OPMLString(indentLevel:0) + return self.feed.OPMLString(indentLevel:0) } // MARK: --- scriptable elements --- @objc(authors) var authors:NSArray { - let feedAuthors = webFeed.authors ?? [] + let feedAuthors = feed.authors ?? [] return feedAuthors.map { ScriptableAuthor($0, container:self) } as NSArray } @objc(valueInAuthorsWithUniqueID:) func valueInAuthors(withUniqueID id:String) -> ScriptableAuthor? { - guard let author = webFeed.authors?.first(where:{$0.authorID == id}) else { return nil } + guard let author = feed.authors?.first(where:{$0.authorID == id}) else { return nil } return ScriptableAuthor(author, container:self) } @objc(articles) var articles:NSArray { - let feedArticles = (try? webFeed.fetchArticles()) ?? Set
() + let feedArticles = (try? feed.fetchArticles()) ?? Set
() // the articles are a set, use the sorting algorithm from the viewer let sortedArticles = feedArticles.sorted(by:{ return $0.logicalDatePublished > $1.logicalDatePublished @@ -193,7 +193,7 @@ final class ScriptableWebFeed: NSObject, UniqueIdScriptingObject, ScriptingObjec @objc(valueInArticlesWithUniqueID:) func valueInArticles(withUniqueID id:String) -> ScriptableArticle? { - let articles = (try? webFeed.fetchArticles()) ?? Set
() + let articles = (try? feed.fetchArticles()) ?? Set
() guard let article = articles.first(where:{$0.uniqueID == id}) else { return nil } return ScriptableArticle(article, container:self) } diff --git a/Mac/Scriptability/Folder+Scriptability.swift b/Mac/Scriptability/Folder+Scriptability.swift index 42689a3f5..bab26ff62 100644 --- a/Mac/Scriptability/Folder+Scriptability.swift +++ b/Mac/Scriptability/Folder+Scriptability.swift @@ -51,9 +51,9 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject } func deleteElement(_ element:ScriptingObject) { - if let scriptableFeed = element as? ScriptableWebFeed { + if let scriptableFeed = element as? ScriptableFeed { BatchUpdate.shared.perform { - folder.account?.removeWebFeed(scriptableFeed.webFeed, from: folder) { result in } + folder.account?.removeFeed(scriptableFeed.feed, from: folder) { result in } } } } @@ -95,19 +95,19 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject // MARK: --- Scriptable elements --- - @objc(webFeeds) - var webFeeds:NSArray { - let feeds = Array(folder.topLevelWebFeeds) - return feeds.map { ScriptableWebFeed($0, container:self) } as NSArray + @objc(feeds) + var feeds:NSArray { + let feeds = Array(folder.topLevelFeeds) + return feeds.map { ScriptableFeed($0, container:self) } as NSArray } @objc(articles) var articles:NSArray { - let feeds = Array(folder.topLevelWebFeeds) + let feeds = Array(folder.topLevelFeeds) let allArticles = feeds.flatMap { feed in (try? feed.fetchArticles()) ?? Set
() } - // Sort articles by logical date published like WebFeed does + // Sort articles by logical date published like Feed does let sortedArticles = allArticles.sorted(by: { return $0.logicalDatePublished > $1.logicalDatePublished }) @@ -116,7 +116,7 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject @objc(countOfArticles) func countOfArticles() -> Int { - let feeds = Array(folder.topLevelWebFeeds) + let feeds = Array(folder.topLevelFeeds) return feeds.reduce(0) { count, feed in let feedArticles = (try? feed.fetchArticles()) ?? Set
() return count + feedArticles.count @@ -125,7 +125,7 @@ final class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObject @objc(objectInArticlesAtIndex:) func objectInArticlesAtIndex(_ index: Int) -> ScriptableArticle? { - let feeds = Array(folder.topLevelWebFeeds) + let feeds = Array(folder.topLevelFeeds) let allArticles = feeds.flatMap { feed in (try? feed.fetchArticles()) ?? Set
() } diff --git a/Mac/Scriptability/NSApplication+Scriptability.swift b/Mac/Scriptability/NSApplication+Scriptability.swift index 2aab6efb0..a3c44d565 100644 --- a/Mac/Scriptability/NSApplication+Scriptability.swift +++ b/Mac/Scriptability/NSApplication+Scriptability.swift @@ -30,8 +30,8 @@ extension NSApplication : ScriptingObjectContainer { func currentArticle() -> ScriptableArticle? { var scriptableArticle: ScriptableArticle? if let currentArticle = appDelegate.scriptingCurrentArticle { - if let feed = currentArticle.webFeed, - let scriptableFeed = ScriptableWebFeed.scriptableWebFeed(for: feed) { + if let feed = currentArticle.feed, + let scriptableFeed = ScriptableFeed.scriptableFeed(for: feed) { scriptableArticle = ScriptableArticle(currentArticle, container: scriptableFeed) } } @@ -42,8 +42,8 @@ extension NSApplication : ScriptingObjectContainer { func selectedArticles() -> NSArray { let articles = appDelegate.scriptingSelectedArticles let scriptableArticles:[ScriptableArticle] = articles.compactMap { article in - if let feed = article.webFeed, - let scriptableFeed = ScriptableWebFeed.scriptableWebFeed(for: feed) { + if let feed = article.feed, + let scriptableFeed = ScriptableFeed.scriptableFeed(for: feed) { return ScriptableArticle(article, container:scriptableFeed) } else { return nil @@ -63,8 +63,8 @@ extension NSApplication : ScriptingObjectContainer { guard index >= 0 && index < articles.count else { return nil } let article = articles[index] - if let feed = article.webFeed, - let scriptableFeed = ScriptableWebFeed.scriptableWebFeed(for: feed) { + if let feed = article.feed, + let scriptableFeed = ScriptableFeed.scriptableFeed(for: feed) { return ScriptableArticle(article, container: scriptableFeed) } else { return nil @@ -104,38 +104,37 @@ extension NSApplication : ScriptingObjectContainer { for 'articles of feed "The Shape of Everything" of account "On My Mac"' */ - func allWebFeeds() -> [WebFeed] { + func allFeeds() -> [Feed] { let accounts = AccountManager.shared.activeAccounts - let emptyFeeds:[WebFeed] = [] - return accounts.reduce(emptyFeeds) { (result, nthAccount) -> [WebFeed] in - let accountFeeds = Array(nthAccount.topLevelWebFeeds) + let emptyFeeds:[Feed] = [] + return accounts.reduce(emptyFeeds) { (result, nthAccount) -> [Feed] in + let accountFeeds = Array(nthAccount.topLevelFeeds) return result + accountFeeds } } - @objc(webFeeds) - func webFeeds() -> NSArray { - let webFeeds = self.allWebFeeds() - return webFeeds.map { ScriptableWebFeed($0, container:self) } as NSArray + @objc(feeds) + func feeds() -> NSArray { + allFeeds().map { ScriptableFeed($0, container:self) } as NSArray } - @objc(countOfWebFeeds) - func countOfWebFeeds() -> Int { - return self.allWebFeeds().count + @objc(countOfFeeds) + func countOfFeeds() -> Int { + allFeeds().count } - @objc(objectInWebFeedsAtIndex:) - func objectInWebFeedsAtIndex(_ index: Int) -> ScriptableWebFeed? { - let webFeeds = self.allWebFeeds() - guard index >= 0 && index < webFeeds.count else { return nil } - return ScriptableWebFeed(webFeeds[index], container: self) + @objc(objectInFeedsAtIndex:) + func objectInFeedsAtIndex(_ index: Int) -> ScriptableFeed? { + let feeds = allFeeds() + guard index >= 0 && index < feeds.count else { return nil } + return ScriptableFeed(feeds[index], container: self) } - @objc(valueInWebFeedsWithUniqueID:) - func valueInWebFeeds(withUniqueID id:String) -> ScriptableWebFeed? { - let webFeeds = self.allWebFeeds() - guard let webFeed = webFeeds.first(where:{$0.webFeedID == id}) else { return nil } - return ScriptableWebFeed(webFeed, container:self) + @objc(valueInFeedsWithUniqueID:) + func valueInFeeds(withUniqueID id:String) -> ScriptableFeed? { + let feeds = allFeeds() + guard let feed = feeds.first(where:{$0.feedID == id}) else { return nil } + return ScriptableFeed(feed, container:self) } } diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index 123d3c187..2f6584b26 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -55,7 +55,7 @@ public enum FetchType { case unread(_: Int? = nil) case today(_: Int? = nil) case folder(Folder, Bool) - case webFeed(WebFeed) + case feed(Feed) case articleIDs(Set) case search(String) case searchWithArticleIDs(String, Set) @@ -72,7 +72,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, public static let articleIDs = "articleIDs" // StatusesDidChange public static let statusKey = "statusKey" // StatusesDidChange public static let statusFlag = "statusFlag" // StatusesDidChange - public static let webFeeds = "webFeeds" // AccountDidDownloadArticles, StatusesDidChange + public static let feeds = "feeds" // AccountDidDownloadArticles, StatusesDidChange public static let syncErrors = "syncErrors" // AccountsDidFailToSyncWithErrors } @@ -126,7 +126,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } - public var topLevelWebFeeds = Set() + public var topLevelFeeds = Set() public var folders: Set? = Set() public var externalID: String? { @@ -145,24 +145,24 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return nil } - private var webFeedDictionariesNeedUpdate = true - private var _idToWebFeedDictionary = [String: WebFeed]() - var idToWebFeedDictionary: [String: WebFeed] { - if webFeedDictionariesNeedUpdate { - rebuildWebFeedDictionaries() + private var feedDictionariesNeedUpdate = true + private var _idToFeedDictionary = [String: Feed]() + var idToFeedDictionary: [String: Feed] { + if feedDictionariesNeedUpdate { + rebuildFeedDictionaries() } - return _idToWebFeedDictionary + return _idToFeedDictionary } - private var _externalIDToWebFeedDictionary = [String: WebFeed]() - var externalIDToWebFeedDictionary: [String: WebFeed] { - if webFeedDictionariesNeedUpdate { - rebuildWebFeedDictionaries() + private var _externalIDToFeedDictionary = [String: Feed]() + var externalIDToFeedDictionary: [String: Feed] { + if feedDictionariesNeedUpdate { + rebuildFeedDictionaries() } - return _externalIDToWebFeedDictionary + return _externalIDToFeedDictionary } - var flattenedWebFeedURLs: Set { - return Set(flattenedWebFeeds().map({ $0.url })) + var flattenedFeedURLs: Set { + return Set(flattenedFeeds().map({ $0.url })) } var username: String? { @@ -197,8 +197,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, private var unreadCounts = [String: Int]() // [feedID: Int] - private var _flattenedWebFeeds = Set() - private var flattenedWebFeedsNeedUpdate = true + private var _flattenedFeeds = Set() + private var flattenedFeedsNeedUpdate = true private lazy var opmlFile = OPMLFile(filename: (dataFolder as NSString).appendingPathComponent("Subscriptions.opml"), account: self) private lazy var metadataFile = AccountMetadataFile(filename: (dataFolder as NSString).appendingPathComponent("Settings.plist"), account: self) @@ -306,7 +306,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, opmlFile.load() DispatchQueue.main.async { - self.database.cleanupDatabaseAtStartup(subscribedToWebFeedIDs: self.flattenedWebFeeds().webFeedIDs()) + self.database.cleanupDatabaseAtStartup(subscribedToFeedIDs: self.flattenedFeeds().feedIDs()) self.fetchAllUnreadCounts() } @@ -471,13 +471,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, func addOPMLItems(_ items: [RSOPMLItem]) { for item in items { if let feedSpecifier = item.feedSpecifier { - addWebFeed(newWebFeed(with: feedSpecifier)) + addFeed(newFeed(with: feedSpecifier)) } else { if let title = item.titleFromAttributes, let folder = ensureFolder(with: title) { folder.externalID = item.attributes?["nnw_externalID"] as? String item.children?.forEach { itemChild in if let feedSpecifier = itemChild.feedSpecifier { - folder.addWebFeed(newWebFeed(with: feedSpecifier)) + folder.addFeed(newFeed(with: feedSpecifier)) } } } @@ -500,13 +500,13 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return existingFolder(withExternalID: externalID) } - public func existingContainers(withWebFeed webFeed: WebFeed) -> [Container] { + public func existingContainers(withFeed feed: Feed) -> [Container] { var containers = [Container]() - if topLevelWebFeeds.contains(webFeed) { + if topLevelFeeds.contains(feed) { containers.append(self) } folders?.forEach { folder in - if folder.topLevelWebFeeds.contains(webFeed) { + if folder.topLevelFeeds.contains(feed) { containers.append(folder) } } @@ -551,10 +551,10 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return folders?.first(where: { $0.externalID == externalID }) } - func newWebFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> WebFeed { + func newFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed { let feedURL = opmlFeedSpecifier.feedURL - let metadata = feedMetadata(feedURL: feedURL, webFeedID: feedURL) - let feed = WebFeed(account: self, url: opmlFeedSpecifier.feedURL, metadata: metadata) + let metadata = feedMetadata(feedURL: feedURL, feedID: feedURL) + let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, metadata: metadata) if let feedTitle = opmlFeedSpecifier.title { if feed.name == nil { feed.name = feedTitle @@ -563,36 +563,36 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return feed } - public func addWebFeed(_ feed: WebFeed, to container: Container, completion: @escaping (Result) -> Void) { - delegate.addWebFeed(for: self, with: feed, to: container, completion: completion) + public func addFeed(_ feed: Feed, to container: Container, completion: @escaping (Result) -> Void) { + delegate.addFeed(for: self, with: feed, to: container, completion: completion) } - public func createWebFeed(url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { - delegate.createWebFeed(for: self, url: url, name: name, container: container, validateFeed: validateFeed, completion: completion) + public func createFeed(url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { + delegate.createFeed(for: self, url: url, name: name, container: container, validateFeed: validateFeed, completion: completion) } - func createWebFeed(with name: String?, url: String, webFeedID: String, homePageURL: String?) -> WebFeed { - let metadata = feedMetadata(feedURL: url, webFeedID: webFeedID) - let feed = WebFeed(account: self, url: url, metadata: metadata) + func createFeed(with name: String?, url: String, feedID: String, homePageURL: String?) -> Feed { + let metadata = feedMetadata(feedURL: url, feedID: feedID) + let feed = Feed(account: self, url: url, metadata: metadata) feed.name = name feed.homePageURL = homePageURL return feed } - public func removeWebFeed(_ feed: WebFeed, from container: Container, completion: @escaping (Result) -> Void) { - delegate.removeWebFeed(for: self, with: feed, from: container, completion: completion) + public func removeFeed(_ feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { + delegate.removeFeed(for: self, with: feed, from: container, completion: completion) } - public func moveWebFeed(_ feed: WebFeed, from: Container, to: Container, completion: @escaping (Result) -> Void) { - delegate.moveWebFeed(for: self, with: feed, from: from, to: to, completion: completion) + public func moveFeed(_ feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + delegate.moveFeed(for: self, with: feed, from: from, to: to, completion: completion) } - public func renameWebFeed(_ feed: WebFeed, to name: String, completion: @escaping (Result) -> Void) { - delegate.renameWebFeed(for: self, with: feed, to: name, completion: completion) + public func renameFeed(_ feed: Feed, to name: String, completion: @escaping (Result) -> Void) { + delegate.renameFeed(for: self, with: feed, to: name, completion: completion) } - public func restoreWebFeed(_ feed: WebFeed, container: Container, completion: @escaping (Result) -> Void) { - delegate.restoreWebFeed(for: self, feed: feed, container: container, completion: completion) + public func restoreFeed(_ feed: Feed, container: Container, completion: @escaping (Result) -> Void) { + delegate.restoreFeed(for: self, feed: feed, container: container, completion: completion) } public func addFolder(_ name: String, completion: @escaping (Result) -> Void) { @@ -611,7 +611,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, delegate.restoreFolder(for: self, folder: folder, completion: completion) } - func clearFeedMetadata(_ feed: WebFeed) { + func clearFeedMetadata(_ feed: Feed) { feedMetadata[feed.url] = nil } @@ -621,8 +621,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, structureDidChange() } - public func updateUnreadCounts(for webFeeds: Set, completion: VoidCompletionBlock? = nil) { - fetchUnreadCounts(for: webFeeds, completion: completion) + public func updateUnreadCounts(for feeds: Set, completion: VoidCompletionBlock? = nil) { + fetchUnreadCounts(for: feeds, completion: completion) } public func fetchArticles(_ fetchType: FetchType) throws -> Set
{ @@ -639,8 +639,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } else { return try fetchArticles(folder: folder) } - case .webFeed(let webFeed): - return try fetchArticles(webFeed: webFeed) + case .feed(let feed): + return try fetchArticles(feed: feed) case .articleIDs(let articleIDs): return try fetchArticles(articleIDs: articleIDs) case .search(let searchString): @@ -664,8 +664,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } else { return fetchArticlesAsync(folder: folder, completion) } - case .webFeed(let webFeed): - fetchArticlesAsync(webFeed: webFeed, completion) + case .feed(let feed): + fetchArticlesAsync(feed: feed, completion) case .articleIDs(let articleIDs): fetchArticlesAsync(articleIDs: articleIDs, completion) case .search(let searchString): @@ -676,15 +676,15 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } public func fetchUnreadCountForToday(_ completion: @escaping SingleUnreadCountCompletionBlock) { - database.fetchUnreadCountForToday(for: flattenedWebFeeds().webFeedIDs(), completion: completion) + database.fetchUnreadCountForToday(for: flattenedFeeds().feedIDs(), completion: completion) } public func fetchUnreadCountForStarredArticles(_ completion: @escaping SingleUnreadCountCompletionBlock) { - database.fetchStarredAndUnreadCount(for: flattenedWebFeeds().webFeedIDs(), completion: completion) + database.fetchStarredAndUnreadCount(for: flattenedFeeds().feedIDs(), completion: completion) } public func fetchCountForStarredArticles() throws -> Int { - return try database.fetchStarredArticlesCount(flattenedWebFeeds().webFeedIDs()) + return try database.fetchStarredArticlesCount(flattenedFeeds().feedIDs()) } public func fetchUnreadArticleIDs(_ completion: @escaping ArticleIDsCompletionBlock) { @@ -700,23 +700,23 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, database.fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate(completion) } - public func unreadCount(for webFeed: WebFeed) -> Int { - return unreadCounts[webFeed.webFeedID] ?? 0 + public func unreadCount(for feed: Feed) -> Int { + return unreadCounts[feed.feedID] ?? 0 } - public func setUnreadCount(_ unreadCount: Int, for webFeed: WebFeed) { - unreadCounts[webFeed.webFeedID] = unreadCount + public func setUnreadCount(_ unreadCount: Int, for feed: Feed) { + unreadCounts[feed.feedID] = unreadCount } public func structureDidChange() { // Feeds were added or deleted. Or folders added or deleted. // Or feeds inside folders were added or deleted. opmlFile.markAsDirty() - flattenedWebFeedsNeedUpdate = true - webFeedDictionariesNeedUpdate = true + flattenedFeedsNeedUpdate = true + feedDictionariesNeedUpdate = true } - @MainActor func update(_ feed: WebFeed, with parsedFeed: ParsedFeed) async throws -> ArticleChanges { + @MainActor func update(_ feed: Feed, with parsedFeed: ParsedFeed) async throws -> ArticleChanges { try await withCheckedThrowingContinuation { continuation in update(feed, with: parsedFeed) { result in switch result { @@ -729,27 +729,27 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } - func update(_ webFeed: WebFeed, with parsedFeed: ParsedFeed, _ completion: @escaping UpdateArticlesCompletionBlock) { + func update(_ feed: Feed, with parsedFeed: ParsedFeed, _ completion: @escaping UpdateArticlesCompletionBlock) { // Used only by an On My Mac or iCloud account. precondition(Thread.isMainThread) precondition(type == .onMyMac || type == .cloudKit) - webFeed.takeSettings(from: parsedFeed) + feed.takeSettings(from: parsedFeed) let parsedItems = parsedFeed.items guard !parsedItems.isEmpty else { completion(.success(ArticleChanges())) return } - update(webFeed.webFeedID, with: parsedItems, completion: completion) + update(feed.feedID, with: parsedItems, completion: completion) } - func update(_ webFeedID: String, with parsedItems: Set, deleteOlder: Bool = true, completion: @escaping UpdateArticlesCompletionBlock) { + func update(_ feedID: String, with parsedItems: Set, deleteOlder: Bool = true, completion: @escaping UpdateArticlesCompletionBlock) { // Used only by an On My Mac or iCloud account. precondition(Thread.isMainThread) precondition(type == .onMyMac || type == .cloudKit) - database.update(with: parsedItems, webFeedID: webFeedID, deleteOlder: deleteOlder) { updateArticlesResult in + database.update(with: parsedItems, feedID: feedID, deleteOlder: deleteOlder) { updateArticlesResult in switch updateArticlesResult { case .success(let articleChanges): self.sendNotificationAbout(articleChanges) @@ -760,16 +760,16 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } - func update(webFeedIDsAndItems: [String: Set], defaultRead: Bool, completion: @escaping DatabaseCompletionBlock) { + func update(feedIDsAndItems: [String: Set], defaultRead: Bool, completion: @escaping DatabaseCompletionBlock) { // Used only by syncing systems. precondition(Thread.isMainThread) precondition(type != .onMyMac && type != .cloudKit) - guard !webFeedIDsAndItems.isEmpty else { + guard !feedIDsAndItems.isEmpty else { completion(nil) return } - database.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: defaultRead) { updateArticlesResult in + database.update(feedIDsAndItems: feedIDsAndItems, defaultRead: defaultRead) { updateArticlesResult in switch updateArticlesResult { case .success(let newAndUpdatedArticles): self.sendNotificationAbout(newAndUpdatedArticles) @@ -877,38 +877,38 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, // MARK: - Container - public func flattenedWebFeeds() -> Set { + public func flattenedFeeds() -> Set { assert(Thread.isMainThread) - if flattenedWebFeedsNeedUpdate { - updateFlattenedWebFeeds() + if flattenedFeedsNeedUpdate { + updateFlattenedFeeds() } - return _flattenedWebFeeds + return _flattenedFeeds } - public func removeWebFeed(_ webFeed: WebFeed) { - topLevelWebFeeds.remove(webFeed) + public func removeFeed(_ feed: Feed) { + topLevelFeeds.remove(feed) structureDidChange() postChildrenDidChangeNotification() } - public func removeFeeds(_ webFeeds: Set) { - guard !webFeeds.isEmpty else { + public func removeFeeds(_ feeds: Set) { + guard !feeds.isEmpty else { return } - topLevelWebFeeds.subtract(webFeeds) + topLevelFeeds.subtract(feeds) structureDidChange() postChildrenDidChangeNotification() } - public func addWebFeed(_ webFeed: WebFeed) { - topLevelWebFeeds.insert(webFeed) + public func addFeed(_ feed: Feed) { + topLevelFeeds.insert(feed) structureDidChange() postChildrenDidChangeNotification() } - func addFeedIfNotInAnyFolder(_ webFeed: WebFeed) { - if !flattenedWebFeeds().contains(webFeed) { - addWebFeed(webFeed) + func addFeedIfNotInAnyFolder(_ feed: Feed) { + if !flattenedFeeds().contains(feed) { + addFeed(feed) } } @@ -922,7 +922,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, public func debugDropConditionalGetInfo() { #if DEBUG - for feed in flattenedWebFeeds() { + for feed in flattenedFeeds() { feed.dropConditionalGetInfo() } #endif @@ -950,14 +950,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } @objc func unreadCountDidChange(_ note: Notification) { - if let feed = note.object as? WebFeed, feed.account === self { + if let feed = note.object as? Feed, feed.account === self { updateUnreadCount() } } @objc func batchUpdateDidPerform(_ note: Notification) { - flattenedWebFeedsNeedUpdate = true - rebuildWebFeedDictionaries() + flattenedFeedsNeedUpdate = true + rebuildFeedDictionaries() updateUnreadCount() } @@ -1007,7 +1007,7 @@ extension Account: FeedMetadataDelegate { func valueDidChange(_ feedMetadata: FeedMetadata, key: FeedMetadata.CodingKeys) { feedMetadataFile.markAsDirty() - guard let feed = existingWebFeed(withWebFeedID: feedMetadata.webFeedID) else { + guard let feed = existingFeed(withFeedID: feedMetadata.feedID) else { return } feed.postFeedSettingDidChangeNotification(key) @@ -1019,11 +1019,11 @@ extension Account: FeedMetadataDelegate { private extension Account { func fetchStarredArticles(limit: Int?) throws -> Set
{ - return try database.fetchStarredArticles(flattenedWebFeeds().webFeedIDs(), limit) + return try database.fetchStarredArticles(flattenedFeeds().feedIDs(), limit) } func fetchStarredArticlesAsync(limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - database.fetchedStarredArticlesAsync(flattenedWebFeeds().webFeedIDs(), limit, completion) + database.fetchedStarredArticlesAsync(flattenedFeeds().feedIDs(), limit, completion) } func fetchUnreadArticles(limit: Int?) throws -> Set
{ @@ -1035,11 +1035,11 @@ private extension Account { } func fetchTodayArticles(limit: Int?) throws -> Set
{ - return try database.fetchTodayArticles(flattenedWebFeeds().webFeedIDs(), limit) + return try database.fetchTodayArticles(flattenedFeeds().feedIDs(), limit) } func fetchTodayArticlesAsync(limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - database.fetchTodayArticlesAsync(flattenedWebFeeds().webFeedIDs(), limit, completion) + database.fetchTodayArticlesAsync(flattenedFeeds().feedIDs(), limit, completion) } func fetchArticles(folder: Folder) throws -> Set
{ @@ -1058,17 +1058,17 @@ private extension Account { fetchUnreadArticlesAsync(forContainer: folder, limit: nil, completion) } - func fetchArticles(webFeed: WebFeed) throws -> Set
{ - let articles = try database.fetchArticles(webFeed.webFeedID) - validateUnreadCount(webFeed, articles) + func fetchArticles(feed: Feed) throws -> Set
{ + let articles = try database.fetchArticles(feed.feedID) + validateUnreadCount(feed, articles) return articles } - func fetchArticlesAsync(webFeed: WebFeed, _ completion: @escaping ArticleSetResultBlock) { - database.fetchArticlesAsync(webFeed.webFeedID) { [weak self] articleSetResult in + func fetchArticlesAsync(feed: Feed, _ completion: @escaping ArticleSetResultBlock) { + database.fetchArticlesAsync(feed.feedID) { [weak self] articleSetResult in switch articleSetResult { case .success(let articles): - self?.validateUnreadCount(webFeed, articles) + self?.validateUnreadCount(feed, articles) completion(.success(articles)) case .failure(let databaseError): completion(.failure(databaseError)) @@ -1077,7 +1077,7 @@ private extension Account { } func fetchArticlesMatching(_ searchString: String) throws -> Set
{ - return try database.fetchArticlesMatching(searchString, flattenedWebFeeds().webFeedIDs()) + return try database.fetchArticlesMatching(searchString, flattenedFeeds().feedIDs()) } func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set) throws -> Set
{ @@ -1085,7 +1085,7 @@ private extension Account { } func fetchArticlesMatchingAsync(_ searchString: String, _ completion: @escaping ArticleSetResultBlock) { - database.fetchArticlesMatchingAsync(searchString, flattenedWebFeeds().webFeedIDs(), completion) + database.fetchArticlesMatchingAsync(searchString, flattenedFeeds().feedIDs(), completion) } func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { @@ -1100,25 +1100,25 @@ private extension Account { return database.fetchArticlesAsync(articleIDs: articleIDs, completion) } - func fetchUnreadArticles(webFeed: WebFeed) throws -> Set
{ - let articles = try database.fetchUnreadArticles(Set([webFeed.webFeedID]), nil) - validateUnreadCount(webFeed, articles) + func fetchUnreadArticles(feed: Feed) throws -> Set
{ + let articles = try database.fetchUnreadArticles(Set([feed.feedID]), nil) + validateUnreadCount(feed, articles) return articles } func fetchArticles(forContainer container: Container) throws -> Set
{ - let feeds = container.flattenedWebFeeds() - let articles = try database.fetchArticles(feeds.webFeedIDs()) + let feeds = container.flattenedFeeds() + let articles = try database.fetchArticles(feeds.feedIDs()) validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles) return articles } func fetchArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetResultBlock) { - let webFeeds = container.flattenedWebFeeds() - database.fetchArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articleSetResult) in + let feeds = container.flattenedFeeds() + database.fetchArticlesAsync(feeds.feedIDs()) { [weak self] (articleSetResult) in switch articleSetResult { case .success(let articles): - self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles) + self?.validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles) completion(.success(articles)) case .failure(let databaseError): completion(.failure(databaseError)) @@ -1127,8 +1127,8 @@ private extension Account { } func fetchUnreadArticles(forContainer container: Container, limit: Int?) throws -> Set
{ - let feeds = container.flattenedWebFeeds() - let articles = try database.fetchUnreadArticles(feeds.webFeedIDs(), limit) + let feeds = container.flattenedFeeds() + let articles = try database.fetchUnreadArticles(feeds.feedIDs(), limit) // We don't validate limit queries because they, by definition, won't correctly match the // complete unread state for the given container. @@ -1140,15 +1140,15 @@ private extension Account { } func fetchUnreadArticlesAsync(forContainer container: Container, limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - let webFeeds = container.flattenedWebFeeds() - database.fetchUnreadArticlesAsync(webFeeds.webFeedIDs(), limit) { [weak self] (articleSetResult) in + let feeds = container.flattenedFeeds() + database.fetchUnreadArticlesAsync(feeds.feedIDs(), limit) { [weak self] (articleSetResult) in switch articleSetResult { case .success(let articles): // We don't validate limit queries because they, by definition, won't correctly match the // complete unread state for the given container. if limit == nil { - self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles) + self?.validateUnreadCountsAfterFetchingUnreadArticles(feeds, articles) } completion(.success(articles)) @@ -1158,34 +1158,34 @@ private extension Account { } } - func validateUnreadCountsAfterFetchingUnreadArticles(_ webFeeds: Set, _ articles: Set
) { + func validateUnreadCountsAfterFetchingUnreadArticles(_ feeds: Set, _ articles: Set
) { // Validate unread counts. This was the site of a performance slowdown: // it was calling going through the entire list of articles once per feed: // feeds.forEach { validateUnreadCount($0, articles) } // Now we loop through articles exactly once. This makes a huge difference. - var unreadCountStorage = [String: Int]() // [WebFeedID: Int] + var unreadCountStorage = [String: Int]() // [FeedID: Int] for article in articles where !article.status.read { - unreadCountStorage[article.webFeedID, default: 0] += 1 + unreadCountStorage[article.feedID, default: 0] += 1 } - webFeeds.forEach { (webFeed) in - let unreadCount = unreadCountStorage[webFeed.webFeedID, default: 0] - webFeed.unreadCount = unreadCount + feeds.forEach { (feed) in + let unreadCount = unreadCountStorage[feed.feedID, default: 0] + feed.unreadCount = unreadCount } } - func validateUnreadCount(_ webFeed: WebFeed, _ articles: Set
) { + func validateUnreadCount(_ feed: Feed, _ articles: Set
) { // articles must contain all the unread articles for the feed. // The unread number should match the feed’s unread count. let feedUnreadCount = articles.reduce(0) { (result, article) -> Int in - if article.webFeed == webFeed && !article.status.read { + if article.feed == feed && !article.status.read { return result + 1 } return result } - webFeed.unreadCount = feedUnreadCount + feed.unreadCount = feedUnreadCount } } @@ -1193,42 +1193,42 @@ private extension Account { private extension Account { - func feedMetadata(feedURL: String, webFeedID: String) -> FeedMetadata { + func feedMetadata(feedURL: String, feedID: String) -> FeedMetadata { if let d = feedMetadata[feedURL] { assert(d.delegate === self) return d } - let d = FeedMetadata(webFeedID: webFeedID) + let d = FeedMetadata(feedID: feedID) d.delegate = self feedMetadata[feedURL] = d return d } - func updateFlattenedWebFeeds() { - var feeds = Set() - feeds.formUnion(topLevelWebFeeds) + func updateFlattenedFeeds() { + var feeds = Set() + feeds.formUnion(topLevelFeeds) for folder in folders! { - feeds.formUnion(folder.flattenedWebFeeds()) + feeds.formUnion(folder.flattenedFeeds()) } - _flattenedWebFeeds = feeds - flattenedWebFeedsNeedUpdate = false + _flattenedFeeds = feeds + flattenedFeedsNeedUpdate = false } - func rebuildWebFeedDictionaries() { - var idDictionary = [String: WebFeed]() - var externalIDDictionary = [String: WebFeed]() + func rebuildFeedDictionaries() { + var idDictionary = [String: Feed]() + var externalIDDictionary = [String: Feed]() - flattenedWebFeeds().forEach { (feed) in - idDictionary[feed.webFeedID] = feed + flattenedFeeds().forEach { (feed) in + idDictionary[feed.feedID] = feed if let externalID = feed.externalID { externalIDDictionary[externalID] = feed } } - _idToWebFeedDictionary = idDictionary - _externalIDToWebFeedDictionary = externalIDDictionary - webFeedDictionariesNeedUpdate = false + _idToFeedDictionary = idDictionary + _externalIDToFeedDictionary = externalIDDictionary + feedDictionariesNeedUpdate = false } func updateUnreadCount() { @@ -1236,14 +1236,14 @@ private extension Account { return } var updatedUnreadCount = 0 - for feed in flattenedWebFeeds() { + for feed in flattenedFeeds() { updatedUnreadCount += feed.unreadCount } unreadCount = updatedUnreadCount } func noteStatusesForArticlesDidChange(_ articles: Set
) { - let feeds = Set(articles.compactMap { $0.webFeed }) + let feeds = Set(articles.compactMap { $0.feed }) let statuses = Set(articles.map { $0.status }) let articleIDs = Set(articles.map { $0.articleID }) @@ -1251,7 +1251,7 @@ private extension Account { // which will update their own unread counts. updateUnreadCounts(for: feeds) - NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.statuses: statuses, UserInfoKey.articles: articles, UserInfoKey.articleIDs: articleIDs, UserInfoKey.webFeeds: feeds]) + NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.statuses: statuses, UserInfoKey.articles: articles, UserInfoKey.articleIDs: articleIDs, UserInfoKey.feeds: feeds]) } func noteStatusesForArticleIDsDidChange(articleIDs: Set, statusKey: ArticleStatus.Key, flag: Bool) { @@ -1267,7 +1267,7 @@ private extension Account { /// Fetch unread counts for zero or more feeds. /// /// Uses the most efficient method based on how many feeds were passed in. - func fetchUnreadCounts(for feeds: Set, completion: VoidCompletionBlock?) { + func fetchUnreadCounts(for feeds: Set, completion: VoidCompletionBlock?) { if feeds.isEmpty { completion?() return @@ -1283,8 +1283,8 @@ private extension Account { } } - func fetchUnreadCount(_ feed: WebFeed, _ completion: VoidCompletionBlock?) { - database.fetchUnreadCount(feed.webFeedID) { result in + func fetchUnreadCount(_ feed: Feed, _ completion: VoidCompletionBlock?) { + database.fetchUnreadCount(feed.feedID) { result in if let unreadCount = try? result.get() { feed.unreadCount = unreadCount } @@ -1292,9 +1292,9 @@ private extension Account { } } - func fetchUnreadCounts(_ feeds: Set, _ completion: VoidCompletionBlock?) { - let webFeedIDs = Set(feeds.map { $0.webFeedID }) - database.fetchUnreadCounts(for: webFeedIDs) { result in + func fetchUnreadCounts(_ feeds: Set, _ completion: VoidCompletionBlock?) { + let feedIDs = Set(feeds.map { $0.feedID }) + database.fetchUnreadCounts(for: feedIDs) { result in if let unreadCountDictionary = try? result.get() { self.processUnreadCounts(unreadCountDictionary: unreadCountDictionary, feeds: feeds) } @@ -1309,7 +1309,7 @@ private extension Account { completion?() return } - self.processUnreadCounts(unreadCountDictionary: unreadCountDictionary, feeds: self.flattenedWebFeeds()) + self.processUnreadCounts(unreadCountDictionary: unreadCountDictionary, feeds: self.flattenedFeeds()) self.fetchingAllUnreadCounts = false self.updateUnreadCount() @@ -1322,22 +1322,22 @@ private extension Account { } } - func processUnreadCounts(unreadCountDictionary: UnreadCountDictionary, feeds: Set) { + func processUnreadCounts(unreadCountDictionary: UnreadCountDictionary, feeds: Set) { for feed in feeds { // When the unread count is zero, it won’t appear in unreadCountDictionary. - let unreadCount = unreadCountDictionary[feed.webFeedID] ?? 0 + let unreadCount = unreadCountDictionary[feed.feedID] ?? 0 feed.unreadCount = unreadCount } } func sendNotificationAbout(_ articleChanges: ArticleChanges) { - var webFeeds = Set() + var feeds = Set() if let newArticles = articleChanges.newArticles { - webFeeds.formUnion(Set(newArticles.compactMap { $0.webFeed })) + feeds.formUnion(Set(newArticles.compactMap { $0.feed })) } if let updatedArticles = articleChanges.updatedArticles { - webFeeds.formUnion(Set(updatedArticles.compactMap { $0.webFeed })) + feeds.formUnion(Set(updatedArticles.compactMap { $0.feed })) } var shouldSendNotification = false @@ -1360,11 +1360,11 @@ private extension Account { } if shouldUpdateUnreadCounts { - self.updateUnreadCounts(for: webFeeds) + self.updateUnreadCounts(for: feeds) } if shouldSendNotification { - userInfo[UserInfoKey.webFeeds] = webFeeds + userInfo[UserInfoKey.feeds] = feeds NotificationCenter.default.post(name: .AccountDidDownloadArticles, object: self, userInfo: userInfo) } } @@ -1374,12 +1374,12 @@ private extension Account { extension Account { - public func existingWebFeed(withWebFeedID webFeedID: String) -> WebFeed? { - return idToWebFeedDictionary[webFeedID] + public func existingFeed(withFeedID feedID: String) -> Feed? { + return idToFeedDictionary[feedID] } - public func existingWebFeed(withExternalID externalID: String) -> WebFeed? { - return externalIDToWebFeedDictionary[externalID] + public func existingFeed(withExternalID externalID: String) -> Feed? { + return externalIDToFeedDictionary[externalID] } } @@ -1390,7 +1390,7 @@ extension Account: OPMLRepresentable { public func OPMLString(indentLevel: Int, allowCustomAttributes: Bool) -> String { var s = "" - for feed in topLevelWebFeeds.sorted() { + for feed in topLevelFeeds.sorted() { s += feed.OPMLString(indentLevel: indentLevel + 1, allowCustomAttributes: allowCustomAttributes) } for folder in folders!.sorted() { diff --git a/Modules/Account/Sources/Account/AccountDelegate.swift b/Modules/Account/Sources/Account/AccountDelegate.swift index 93a998561..a8981bc6a 100644 --- a/Modules/Account/Sources/Account/AccountDelegate.swift +++ b/Modules/Account/Sources/Account/AccountDelegate.swift @@ -36,13 +36,13 @@ protocol AccountDelegate { func renameFolder(for account: Account, with folder: Folder, to name: String, completion: @escaping (Result) -> Void) func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) - func createWebFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) - func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result) -> Void) - func addWebFeed(for account: Account, with: WebFeed, to container: Container, completion: @escaping (Result) -> Void) - func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result) -> Void) - func moveWebFeed(for account: Account, with feed: WebFeed, from: Container, to: Container, completion: @escaping (Result) -> Void) + func createFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) + func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) + func addFeed(for account: Account, with: Feed, to container: Container, completion: @escaping (Result) -> Void) + func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) - func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result) -> Void) + func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result) -> Void) func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) func markArticles(for account: Account, articles: Set
, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping (Result) -> Void) diff --git a/Modules/Account/Sources/Account/AccountManager.swift b/Modules/Account/Sources/Account/AccountManager.swift index cf188d0e9..9c01efaee 100644 --- a/Modules/Account/Sources/Account/AccountManager.swift +++ b/Modules/Account/Sources/Account/AccountManager.swift @@ -216,9 +216,9 @@ public final class AccountManager: UnreadCountProvider { if let account = existingAccount(with: accountID) { return account.existingFolder(with: folderName) } - case .webFeed(let accountID, let webFeedID): + case .feed(let accountID, let feedID): if let account = existingAccount(with: accountID) { - return account.existingWebFeed(withWebFeedID: webFeedID) + return account.existingFeed(withFeedID: feedID) } default: break @@ -321,7 +321,7 @@ public final class AccountManager: UnreadCountProvider { public func anyAccountHasAtLeastOneFeed() -> Bool { for account in activeAccounts { - if account.hasAtLeastOneWebFeed() { + if account.hasAtLeastOneFeed() { return true } } @@ -335,7 +335,7 @@ public final class AccountManager: UnreadCountProvider { public func anyAccountHasFeedWithURL(_ urlString: String) -> Bool { for account in activeAccounts { - if let _ = account.existingWebFeed(withURL: urlString) { + if let _ = account.existingFeed(withURL: urlString) { return true } } diff --git a/Modules/Account/Sources/Account/ArticleFetcher.swift b/Modules/Account/Sources/Account/ArticleFetcher.swift index 308cb155e..007c66e17 100644 --- a/Modules/Account/Sources/Account/ArticleFetcher.swift +++ b/Modules/Account/Sources/Account/ArticleFetcher.swift @@ -18,10 +18,10 @@ public protocol ArticleFetcher { func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) } -extension WebFeed: ArticleFetcher { +extension Feed: ArticleFetcher { public func fetchArticles() throws -> Set
{ - return try account?.fetchArticles(.webFeed(self)) ?? Set
() + return try account?.fetchArticles(.feed(self)) ?? Set
() } public func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) { @@ -30,7 +30,7 @@ extension WebFeed: ArticleFetcher { completion(.success(Set
())) return } - account.fetchArticlesAsync(.webFeed(self), completion) + account.fetchArticlesAsync(.feed(self), completion) } public func fetchUnreadArticles() throws -> Set
{ @@ -43,7 +43,7 @@ extension WebFeed: ArticleFetcher { completion(.success(Set
())) return } - account.fetchArticlesAsync(.webFeed(self)) { articleSetResult in + account.fetchArticlesAsync(.feed(self)) { articleSetResult in switch articleSetResult { case .success(let articles): completion(.success(articles.unreadArticles())) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 4152d122f..4b7d30599 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -182,7 +182,7 @@ final class CloudKitAccountDelegate: AccountDelegate { } } - func createWebFeed(for account: Account, url urlString: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { + func createFeed(for account: Account, url urlString: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { guard let url = URL(string: urlString) else { completion(.failure(LocalAccountDelegateError.invalidParameter)) return @@ -190,13 +190,13 @@ final class CloudKitAccountDelegate: AccountDelegate { let editedName = name == nil || name!.isEmpty ? nil : name - createRSSWebFeed(for: account, url: url, editedName: editedName, container: container, validateFeed: validateFeed, completion: completion) + createRSSFeed(for: account, url: url, editedName: editedName, container: container, validateFeed: validateFeed, completion: completion) } - func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result) -> Void) { + func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { let editedName = name.isEmpty ? nil : name syncProgress.addToNumberOfTasksAndRemaining(1) - accountZone.renameWebFeed(feed, editedName: editedName) { result in + accountZone.renameFeed(feed, editedName: editedName) { result in self.syncProgress.completeTask() switch result { case .success: @@ -209,19 +209,19 @@ final class CloudKitAccountDelegate: AccountDelegate { } } - func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result) -> Void) { - removeWebFeedFromCloud(for: account, with: feed, from: container) { result in + func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { + removeFeedFromCloud(for: account, with: feed, from: container) { result in switch result { case .success: account.clearFeedMetadata(feed) - container.removeWebFeed(feed) + container.removeFeed(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.clearFeedMetadata(feed) - container.removeWebFeed(feed) + container.removeFeed(feed) default: completion(.failure(error)) } @@ -229,14 +229,14 @@ final class CloudKitAccountDelegate: AccountDelegate { } } - func moveWebFeed(for account: Account, with feed: WebFeed, from fromContainer: Container, to toContainer: Container, completion: @escaping (Result) -> Void) { + func moveFeed(for account: Account, with feed: Feed, from fromContainer: Container, to toContainer: Container, completion: @escaping (Result) -> Void) { syncProgress.addToNumberOfTasksAndRemaining(1) - accountZone.moveWebFeed(feed, from: fromContainer, to: toContainer) { result in + accountZone.moveFeed(feed, from: fromContainer, to: toContainer) { result in self.syncProgress.completeTask() switch result { case .success: - fromContainer.removeWebFeed(feed) - toContainer.addWebFeed(feed) + fromContainer.removeFeed(feed) + toContainer.addFeed(feed) completion(.success(())) case .failure(let error): self.processAccountError(account, error) @@ -245,13 +245,13 @@ final class CloudKitAccountDelegate: AccountDelegate { } } - func addWebFeed(for account: Account, with feed: WebFeed, to container: Container, completion: @escaping (Result) -> Void) { + func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result) -> Void) { syncProgress.addToNumberOfTasksAndRemaining(1) - accountZone.addWebFeed(feed, to: container) { result in + accountZone.addFeed(feed, to: container) { result in self.syncProgress.completeTask() switch result { case .success: - container.addWebFeed(feed) + container.addFeed(feed) completion(.success(())) case .failure(let error): self.processAccountError(account, error) @@ -260,8 +260,8 @@ final class CloudKitAccountDelegate: AccountDelegate { } } - func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result) -> Void) { - createWebFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in + func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result) -> Void) { + createFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in switch result { case .success: completion(.success(())) @@ -308,21 +308,21 @@ final class CloudKitAccountDelegate: AccountDelegate { func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { syncProgress.addToNumberOfTasksAndRemaining(2) - accountZone.findWebFeedExternalIDs(for: folder) { result in + accountZone.findFeedExternalIDs(for: folder) { result in self.syncProgress.completeTask() switch result { - case .success(let webFeedExternalIDs): + case .success(let feedExternalIDs): - let webFeeds = webFeedExternalIDs.compactMap { account.existingWebFeed(withExternalID: $0) } + let feeds = feedExternalIDs.compactMap { account.existingFeed(withExternalID: $0) } let group = DispatchGroup() var errorOccurred = false - for webFeed in webFeeds { + for feed in feeds { group.enter() - self.removeWebFeedFromCloud(for: account, with: webFeed, from: folder) { result in + self.removeFeedFromCloud(for: account, with: feed, from: folder) { result in group.leave() if case .failure(let error) = result { - Self.logger.error("CloudKit: Remove folder, remove webfeed error: \(error.localizedDescription)") + Self.logger.error("CloudKit: Remove folder, remove feed error: \(error.localizedDescription)") errorOccurred = true } } @@ -365,7 +365,7 @@ final class CloudKitAccountDelegate: AccountDelegate { return } - let feedsToRestore = folder.topLevelWebFeeds + let feedsToRestore = folder.topLevelFeeds syncProgress.addToNumberOfTasksAndRemaining(1 + feedsToRestore.count) accountZone.createFolder(name: name) { result in @@ -378,10 +378,10 @@ final class CloudKitAccountDelegate: AccountDelegate { let group = DispatchGroup() for feed in feedsToRestore { - folder.topLevelWebFeeds.remove(feed) + folder.topLevelFeeds.remove(feed) group.enter() - self.restoreWebFeed(for: account, feed: feed, container: folder) { result in + self.restoreFeed(for: account, feed: feed, container: folder) { result in self.syncProgress.completeTask() group.leave() switch result { @@ -521,7 +521,7 @@ private extension CloudKitAccountDelegate { accountZone.fetchChangesInZone() { result in self.syncProgress.completeTask() - let webFeeds = account.flattenedWebFeeds() + let feeds = account.flattenedFeeds() switch result { case .success: @@ -530,7 +530,7 @@ private extension CloudKitAccountDelegate { switch result { case .success: - self.combinedRefresh(account, webFeeds) { + self.combinedRefresh(account, feeds) { self.syncProgress.reset() account.metadata.lastArticleFetchEndTime = Date() } @@ -560,13 +560,13 @@ private extension CloudKitAccountDelegate { case .success: self.syncProgress.completeTask() - let webFeeds = account.flattenedWebFeeds() + let feeds = account.flattenedFeeds() self.refreshArticleStatus(for: account) { result in switch result { case .success: self.syncProgress.completeTask() - self.combinedRefresh(account, webFeeds) { + self.combinedRefresh(account, feeds) { self.sendArticleStatus(for: account, showProgress: true) { _ in self.syncProgress.reset() account.metadata.lastArticleFetchEndTime = Date() @@ -584,18 +584,18 @@ private extension CloudKitAccountDelegate { } } - func combinedRefresh(_ account: Account, _ webFeeds: Set, completion: @escaping () -> Void) { + func combinedRefresh(_ account: Account, _ feeds: Set, completion: @escaping () -> Void) { - refresher.refreshFeeds(webFeeds, completion: completion) + refresher.refreshFeeds(feeds, completion: completion) } - func createRSSWebFeed(for account: Account, url: URL, editedName: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { + func createRSSFeed(for account: Account, url: URL, editedName: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { func addDeadFeed() { - let feed = account.createWebFeed(with: editedName, url: url.absoluteString, webFeedID: url.absoluteString, homePageURL: nil) - container.addWebFeed(feed) + let feed = account.createFeed(with: editedName, url: url.absoluteString, feedID: url.absoluteString, homePageURL: nil) + container.addFeed(feed) - self.accountZone.createWebFeed(url: url.absoluteString, + self.accountZone.createFeed(url: url.absoluteString, name: editedName, editedName: nil, homePageURL: nil, @@ -607,7 +607,7 @@ private extension CloudKitAccountDelegate { feed.externalID = externalID completion(.success(feed)) case .failure(let error): - container.removeWebFeed(feed) + container.removeFeed(feed) completion(.failure(error)) } } @@ -630,15 +630,15 @@ private extension CloudKitAccountDelegate { return } - if account.hasWebFeed(withURL: bestFeedSpecifier.urlString) { + if account.hasFeed(withURL: bestFeedSpecifier.urlString) { self.syncProgress.completeTasks(4) completion(.failure(AccountError.createErrorAlreadySubscribed)) return } - let feed = account.createWebFeed(with: nil, url: url.absoluteString, webFeedID: url.absoluteString, homePageURL: nil) + let feed = account.createFeed(with: nil, url: url.absoluteString, feedID: url.absoluteString, homePageURL: nil) feed.editedName = editedName - container.addWebFeed(feed) + container.addFeed(feed) InitialFeedDownloader.download(url) { parsedFeed, _, response, _ in self.syncProgress.completeTask() @@ -655,7 +655,7 @@ private extension CloudKitAccountDelegate { switch result { case .success: - self.accountZone.createWebFeed(url: bestFeedSpecifier.urlString, + self.accountZone.createFeed(url: bestFeedSpecifier.urlString, name: parsedFeed.title, editedName: editedName, homePageURL: parsedFeed.homePageURL, @@ -668,14 +668,14 @@ private extension CloudKitAccountDelegate { self.sendNewArticlesToTheCloud(account, feed) completion(.success(feed)) case .failure(let error): - container.removeWebFeed(feed) + container.removeFeed(feed) self.syncProgress.completeTasks(2) completion(.failure(error)) } } case .failure(let error): - container.removeWebFeed(feed) + container.removeFeed(feed) self.syncProgress.completeTasks(3) completion(.failure(error)) } @@ -683,7 +683,7 @@ private extension CloudKitAccountDelegate { } } else { self.syncProgress.completeTasks(3) - container.removeWebFeed(feed) + container.removeFeed(feed) completion(.failure(AccountError.createErrorNotFound)) } @@ -702,8 +702,8 @@ private extension CloudKitAccountDelegate { } } - func sendNewArticlesToTheCloud(_ account: Account, _ feed: WebFeed) { - account.fetchArticlesAsync(.webFeed(feed)) { result in + func sendNewArticlesToTheCloud(_ account: Account, _ feed: Feed) { + account.fetchArticlesAsync(.feed(feed)) { result in switch result { case .success(let articles): self.storeArticleChanges(new: articles, updated: Set
(), deleted: Set
()) { @@ -725,7 +725,7 @@ private extension CloudKitAccountDelegate { func processAccountError(_ account: Account, _ error: Error) { if case CloudKitZoneError.userDeletedZone = error { - account.removeFeeds(account.topLevelWebFeeds) + account.removeFeeds(account.topLevelFeeds) for folder in account.folders ?? Set() { account.removeFolder(folder) } @@ -790,17 +790,17 @@ private extension CloudKitAccountDelegate { } - func removeWebFeedFromCloud(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result) -> Void) { + func removeFeedFromCloud(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { syncProgress.addToNumberOfTasksAndRemaining(2) - accountZone.removeWebFeed(feed, from: container) { result in + accountZone.removeFeed(feed, from: container) { result in self.syncProgress.completeTask() switch result { case .success: - guard let webFeedExternalID = feed.externalID else { + guard let feedExternalID = feed.externalID else { completion(.success(())) return } - self.articlesZone.deleteArticles(webFeedExternalID) { result in + self.articlesZone.deleteArticles(feedExternalID) { result in feed.dropConditionalGetInfo() self.syncProgress.completeTask() completion(result) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountZone.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountZone.swift index dbb43b8ec..c2339e5d6 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountZone.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountZone.swift @@ -27,7 +27,7 @@ final class CloudKitAccountZone: CloudKitZone { weak var database: CKDatabase? var delegate: CloudKitZoneDelegate? - struct CloudKitWebFeed { + struct CloudKitFeed { static let recordType = "AccountWebFeed" struct Fields { static let url = "url" @@ -58,13 +58,13 @@ final class CloudKitAccountZone: CloudKitZone { var feedRecords = [String: CKRecord]() func processFeed(feedSpecifier: RSOPMLFeedSpecifier, containerExternalID: String) { - if let webFeedRecord = feedRecords[feedSpecifier.feedURL], var containerExternalIDs = webFeedRecord[CloudKitWebFeed.Fields.containerExternalIDs] as? [String] { + if let feedRecord = feedRecords[feedSpecifier.feedURL], var containerExternalIDs = feedRecord[CloudKitFeed.Fields.containerExternalIDs] as? [String] { containerExternalIDs.append(containerExternalID) - webFeedRecord[CloudKitWebFeed.Fields.containerExternalIDs] = containerExternalIDs + feedRecord[CloudKitFeed.Fields.containerExternalIDs] = containerExternalIDs } else { - let webFeedRecord = newWebFeedCKRecord(feedSpecifier: feedSpecifier, containerExternalID: containerExternalID) - records.append(webFeedRecord) - feedRecords[feedSpecifier.feedURL] = webFeedRecord + let feedRecord = newFeedCKRecord(feedSpecifier: feedSpecifier, containerExternalID: containerExternalID) + records.append(feedRecord) + feedRecords[feedSpecifier.feedURL] = feedRecord } } @@ -88,23 +88,23 @@ final class CloudKitAccountZone: CloudKitZone { } /// Persist a web feed record to iCloud and return the external key - func createWebFeed(url: String, name: String?, editedName: String?, homePageURL: String?, container: Container, completion: @escaping (Result) -> Void) { + func createFeed(url: String, name: String?, editedName: String?, homePageURL: String?, container: Container, completion: @escaping (Result) -> Void) { let recordID = CKRecord.ID(recordName: url.md5String, zoneID: zoneID) - let record = CKRecord(recordType: CloudKitWebFeed.recordType, recordID: recordID) - record[CloudKitWebFeed.Fields.url] = url - record[CloudKitWebFeed.Fields.name] = name + let record = CKRecord(recordType: CloudKitFeed.recordType, recordID: recordID) + record[CloudKitFeed.Fields.url] = url + record[CloudKitFeed.Fields.name] = name if let editedName = editedName { - record[CloudKitWebFeed.Fields.editedName] = editedName + record[CloudKitFeed.Fields.editedName] = editedName } if let homePageURL = homePageURL { - record[CloudKitWebFeed.Fields.homePageURL] = homePageURL + record[CloudKitFeed.Fields.homePageURL] = homePageURL } guard let containerExternalID = container.externalID else { completion(.failure(CloudKitZoneError.corruptAccount)) return } - record[CloudKitWebFeed.Fields.containerExternalIDs] = [containerExternalID] + record[CloudKitFeed.Fields.containerExternalIDs] = [containerExternalID] save(record) { result in switch result { @@ -117,15 +117,15 @@ final class CloudKitAccountZone: CloudKitZone { } /// Rename the given web feed - func renameWebFeed(_ webFeed: WebFeed, editedName: String?, completion: @escaping (Result) -> Void) { - guard let externalID = webFeed.externalID else { + func renameFeed(_ feed: Feed, editedName: String?, completion: @escaping (Result) -> Void) { + guard let externalID = feed.externalID else { completion(.failure(CloudKitZoneError.corruptAccount)) return } let recordID = CKRecord.ID(recordName: externalID, zoneID: zoneID) - let record = CKRecord(recordType: CloudKitWebFeed.recordType, recordID: recordID) - record[CloudKitWebFeed.Fields.editedName] = editedName + let record = CKRecord(recordType: CloudKitFeed.recordType, recordID: recordID) + record[CloudKitFeed.Fields.editedName] = editedName save(record) { result in switch result { @@ -138,22 +138,22 @@ final class CloudKitAccountZone: CloudKitZone { } /// Removes a web feed from a container and optionally deletes it, calling the completion with true if deleted - func removeWebFeed(_ webFeed: WebFeed, from: Container, completion: @escaping (Result) -> Void) { + func removeFeed(_ feed: Feed, from: Container, completion: @escaping (Result) -> Void) { guard let fromContainerExternalID = from.externalID else { completion(.failure(CloudKitZoneError.corruptAccount)) return } - fetch(externalID: webFeed.externalID) { result in + fetch(externalID: feed.externalID) { result in switch result { case .success(let record): - if let containerExternalIDs = record[CloudKitWebFeed.Fields.containerExternalIDs] as? [String] { + if let containerExternalIDs = record[CloudKitFeed.Fields.containerExternalIDs] as? [String] { var containerExternalIDSet = Set(containerExternalIDs) containerExternalIDSet.remove(fromContainerExternalID) if containerExternalIDSet.isEmpty { - self.delete(externalID: webFeed.externalID) { result in + self.delete(externalID: feed.externalID) { result in switch result { case .success: completion(.success(true)) @@ -164,7 +164,7 @@ final class CloudKitAccountZone: CloudKitZone { } else { - record[CloudKitWebFeed.Fields.containerExternalIDs] = Array(containerExternalIDSet) + record[CloudKitFeed.Fields.containerExternalIDs] = Array(containerExternalIDSet) self.save(record) { result in switch result { case .success: @@ -187,20 +187,20 @@ final class CloudKitAccountZone: CloudKitZone { } } - func moveWebFeed(_ webFeed: WebFeed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + func moveFeed(_ feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { guard let fromContainerExternalID = from.externalID, let toContainerExternalID = to.externalID else { completion(.failure(CloudKitZoneError.corruptAccount)) return } - fetch(externalID: webFeed.externalID) { result in + fetch(externalID: feed.externalID) { result in switch result { case .success(let record): - if let containerExternalIDs = record[CloudKitWebFeed.Fields.containerExternalIDs] as? [String] { + if let containerExternalIDs = record[CloudKitFeed.Fields.containerExternalIDs] as? [String] { var containerExternalIDSet = Set(containerExternalIDs) containerExternalIDSet.remove(fromContainerExternalID) containerExternalIDSet.insert(toContainerExternalID) - record[CloudKitWebFeed.Fields.containerExternalIDs] = Array(containerExternalIDSet) + record[CloudKitFeed.Fields.containerExternalIDs] = Array(containerExternalIDSet) self.save(record, completion: completion) } case .failure(let error): @@ -209,19 +209,19 @@ final class CloudKitAccountZone: CloudKitZone { } } - func addWebFeed(_ webFeed: WebFeed, to: Container, completion: @escaping (Result) -> Void) { + func addFeed(_ feed: Feed, to: Container, completion: @escaping (Result) -> Void) { guard let toContainerExternalID = to.externalID else { completion(.failure(CloudKitZoneError.corruptAccount)) return } - fetch(externalID: webFeed.externalID) { result in + fetch(externalID: feed.externalID) { result in switch result { case .success(let record): - if let containerExternalIDs = record[CloudKitWebFeed.Fields.containerExternalIDs] as? [String] { + if let containerExternalIDs = record[CloudKitFeed.Fields.containerExternalIDs] as? [String] { var containerExternalIDSet = Set(containerExternalIDs) containerExternalIDSet.insert(toContainerExternalID) - record[CloudKitWebFeed.Fields.containerExternalIDs] = Array(containerExternalIDSet) + record[CloudKitFeed.Fields.containerExternalIDs] = Array(containerExternalIDSet) self.save(record, completion: completion) } case .failure(let error): @@ -230,20 +230,20 @@ final class CloudKitAccountZone: CloudKitZone { } } - func findWebFeedExternalIDs(for folder: Folder, completion: @escaping (Result<[String], Error>) -> Void) { + func findFeedExternalIDs(for folder: Folder, completion: @escaping (Result<[String], Error>) -> Void) { guard let folderExternalID = folder.externalID else { completion(.failure(CloudKitAccountZoneError.unknown)) return } let predicate = NSPredicate(format: "containerExternalIDs CONTAINS %@", folderExternalID) - let ckQuery = CKQuery(recordType: CloudKitWebFeed.recordType, predicate: predicate) + let ckQuery = CKQuery(recordType: CloudKitFeed.recordType, predicate: predicate) query(ckQuery) { result in switch result { case .success(let records): - let webFeedExternalIds = records.map { $0.externalID } - completion(.success(webFeedExternalIds)) + let feedExternalIds = records.map { $0.externalID } + completion(.success(feedExternalIds)) case .failure(let error): completion(.failure(error)) } @@ -328,16 +328,16 @@ final class CloudKitAccountZone: CloudKitZone { private extension CloudKitAccountZone { - func newWebFeedCKRecord(feedSpecifier: RSOPMLFeedSpecifier, containerExternalID: String) -> CKRecord { - let record = CKRecord(recordType: CloudKitWebFeed.recordType, recordID: generateRecordID()) - record[CloudKitWebFeed.Fields.url] = feedSpecifier.feedURL + func newFeedCKRecord(feedSpecifier: RSOPMLFeedSpecifier, containerExternalID: String) -> CKRecord { + let record = CKRecord(recordType: CloudKitFeed.recordType, recordID: generateRecordID()) + record[CloudKitFeed.Fields.url] = feedSpecifier.feedURL if let editedName = feedSpecifier.title { - record[CloudKitWebFeed.Fields.editedName] = editedName + record[CloudKitFeed.Fields.editedName] = editedName } if let homePageURL = feedSpecifier.homePageURL { - record[CloudKitWebFeed.Fields.homePageURL] = homePageURL + record[CloudKitFeed.Fields.homePageURL] = homePageURL } - record[CloudKitWebFeed.Fields.containerExternalIDs] = [containerExternalID] + record[CloudKitFeed.Fields.containerExternalIDs] = [containerExternalID] return record } diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift index 1938adb79..007b14d7f 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift @@ -15,9 +15,9 @@ import Articles final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate { - private typealias UnclaimedWebFeed = (url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String) - private var newUnclaimedWebFeeds = [String: [UnclaimedWebFeed]]() - private var existingUnclaimedWebFeeds = [String: [WebFeed]]() + private typealias UnclaimedFeed = (url: URL, name: String?, editedName: String?, homePageURL: String?, feedExternalID: String) + private var newUnclaimedFeeds = [String: [UnclaimedFeed]]() + private var existingUnclaimedFeeds = [String: [Feed]]() weak var account: Account? weak var articlesZone: CloudKitArticlesZone? @@ -30,8 +30,8 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate { func cloudKitDidModify(changed: [CKRecord], deleted: [CloudKitRecordKey], completion: @escaping (Result) -> Void) { for deletedRecordKey in deleted { switch deletedRecordKey.recordType { - case CloudKitAccountZone.CloudKitWebFeed.recordType: - removeWebFeed(deletedRecordKey.recordID.externalID) + case CloudKitAccountZone.CloudKitFeed.recordType: + removeFeed(deletedRecordKey.recordID.externalID) case CloudKitAccountZone.CloudKitContainer.recordType: removeContainer(deletedRecordKey.recordID.externalID) default: @@ -41,8 +41,8 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate { for changedRecord in changed { switch changedRecord.recordType { - case CloudKitAccountZone.CloudKitWebFeed.recordType: - addOrUpdateWebFeed(changedRecord) + case CloudKitAccountZone.CloudKitFeed.recordType: + addOrUpdateFeed(changedRecord) case CloudKitAccountZone.CloudKitContainer.recordType: addOrUpdateContainer(changedRecord) default: @@ -53,36 +53,36 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate { completion(.success(())) } - func addOrUpdateWebFeed(_ record: CKRecord) { + func addOrUpdateFeed(_ record: CKRecord) { guard let account = account, - let urlString = record[CloudKitAccountZone.CloudKitWebFeed.Fields.url] as? String, - let containerExternalIDs = record[CloudKitAccountZone.CloudKitWebFeed.Fields.containerExternalIDs] as? [String], + let urlString = record[CloudKitAccountZone.CloudKitFeed.Fields.url] as? String, + let containerExternalIDs = record[CloudKitAccountZone.CloudKitFeed.Fields.containerExternalIDs] as? [String], let url = URL(string: urlString) else { return } - let name = record[CloudKitAccountZone.CloudKitWebFeed.Fields.name] as? String - let editedName = record[CloudKitAccountZone.CloudKitWebFeed.Fields.editedName] as? String - let homePageURL = record[CloudKitAccountZone.CloudKitWebFeed.Fields.homePageURL] as? String + let name = record[CloudKitAccountZone.CloudKitFeed.Fields.name] as? String + let editedName = record[CloudKitAccountZone.CloudKitFeed.Fields.editedName] as? String + let homePageURL = record[CloudKitAccountZone.CloudKitFeed.Fields.homePageURL] as? String - if let webFeed = account.existingWebFeed(withExternalID: record.externalID) { - updateWebFeed(webFeed, name: name, editedName: editedName, homePageURL: homePageURL, containerExternalIDs: containerExternalIDs) + if let feed = account.existingFeed(withExternalID: record.externalID) { + updateFeed(feed, name: name, editedName: editedName, homePageURL: homePageURL, containerExternalIDs: containerExternalIDs) } else { for containerExternalID in containerExternalIDs { if let container = account.existingContainer(withExternalID: containerExternalID) { - createWebFeedIfNecessary(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: record.externalID, container: container) + createFeedIfNecessary(url: url, name: name, editedName: editedName, homePageURL: homePageURL, feedExternalID: record.externalID, container: container) } else { - addNewUnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: record.externalID, containerExternalID: containerExternalID) + addNewUnclaimedFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, feedExternalID: record.externalID, containerExternalID: containerExternalID) } } } } - func removeWebFeed(_ externalID: String) { - if let webFeed = account?.existingWebFeed(withExternalID: externalID), let containers = account?.existingContainers(withWebFeed: webFeed) { + func removeFeed(_ externalID: String) { + if let feed = account?.existingFeed(withExternalID: externalID), let containers = account?.existingContainers(withFeed: feed) { for container in containers { - webFeed.dropConditionalGetInfo() - container.removeWebFeed(webFeed) + feed.dropConditionalGetInfo() + container.removeFeed(feed) } } } @@ -105,24 +105,24 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate { guard let container = folder, let containerExternalID = container.externalID else { return } - if let newUnclaimedWebFeeds = newUnclaimedWebFeeds[containerExternalID] { - for newUnclaimedWebFeed in newUnclaimedWebFeeds { - createWebFeedIfNecessary(url: newUnclaimedWebFeed.url, - name: newUnclaimedWebFeed.name, - editedName: newUnclaimedWebFeed.editedName, - homePageURL: newUnclaimedWebFeed.homePageURL, - webFeedExternalID: newUnclaimedWebFeed.webFeedExternalID, + if let newUnclaimedFeeds = newUnclaimedFeeds[containerExternalID] { + for newUnclaimedFeed in newUnclaimedFeeds { + createFeedIfNecessary(url: newUnclaimedFeed.url, + name: newUnclaimedFeed.name, + editedName: newUnclaimedFeed.editedName, + homePageURL: newUnclaimedFeed.homePageURL, + feedExternalID: newUnclaimedFeed.feedExternalID, container: container) } - self.newUnclaimedWebFeeds.removeValue(forKey: containerExternalID) + self.newUnclaimedFeeds.removeValue(forKey: containerExternalID) } - if let existingUnclaimedWebFeeds = existingUnclaimedWebFeeds[containerExternalID] { - for existingUnclaimedWebFeed in existingUnclaimedWebFeeds { - container.addWebFeed(existingUnclaimedWebFeed) + if let existingUnclaimedFeeds = existingUnclaimedFeeds[containerExternalID] { + for existingUnclaimedFeed in existingUnclaimedFeeds { + container.addFeed(existingUnclaimedFeed) } - self.existingUnclaimedWebFeeds.removeValue(forKey: containerExternalID) + self.existingUnclaimedFeeds.removeValue(forKey: containerExternalID) } } @@ -136,14 +136,14 @@ final class CloudKitAcountZoneDelegate: CloudKitZoneDelegate { private extension CloudKitAcountZoneDelegate { - func updateWebFeed(_ webFeed: WebFeed, name: String?, editedName: String?, homePageURL: String?, containerExternalIDs: [String]) { + func updateFeed(_ feed: Feed, name: String?, editedName: String?, homePageURL: String?, containerExternalIDs: [String]) { guard let account = account else { return } - webFeed.name = name - webFeed.editedName = editedName - webFeed.homePageURL = homePageURL + feed.name = name + feed.editedName = editedName + feed.homePageURL = homePageURL - let existingContainers = account.existingContainers(withWebFeed: webFeed) + let existingContainers = account.existingContainers(withFeed: feed) let existingContainerExternalIds = existingContainers.compactMap { $0.externalID } let diff = containerExternalIDs.difference(from: existingContainerExternalIds) @@ -152,50 +152,50 @@ private extension CloudKitAcountZoneDelegate { switch change { case .remove(_, let externalID, _): if let container = existingContainers.first(where: { $0.externalID == externalID }) { - container.removeWebFeed(webFeed) + container.removeFeed(feed) } case .insert(_, let externalID, _): if let container = account.existingContainer(withExternalID: externalID) { - container.addWebFeed(webFeed) + container.addFeed(feed) } else { - addExistingUnclaimedWebFeed(webFeed, containerExternalID: externalID) + addExistingUnclaimedFeed(feed, containerExternalID: externalID) } } } } - func createWebFeedIfNecessary(url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String, container: Container) { + func createFeedIfNecessary(url: URL, name: String?, editedName: String?, homePageURL: String?, feedExternalID: String, container: Container) { guard let account = account else { return } - if account.existingWebFeed(withExternalID: webFeedExternalID) != nil { + if account.existingFeed(withExternalID: feedExternalID) != nil { return } - let webFeed = account.createWebFeed(with: name, url: url.absoluteString, webFeedID: url.absoluteString, homePageURL: homePageURL) - webFeed.editedName = editedName - webFeed.externalID = webFeedExternalID - container.addWebFeed(webFeed) + let feed = account.createFeed(with: name, url: url.absoluteString, feedID: url.absoluteString, homePageURL: homePageURL) + feed.editedName = editedName + feed.externalID = feedExternalID + container.addFeed(feed) } - func addNewUnclaimedWebFeed(url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String, containerExternalID: String) { - if var unclaimedWebFeeds = self.newUnclaimedWebFeeds[containerExternalID] { - unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID)) - self.newUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds + func addNewUnclaimedFeed(url: URL, name: String?, editedName: String?, homePageURL: String?, feedExternalID: String, containerExternalID: String) { + if var unclaimedFeeds = self.newUnclaimedFeeds[containerExternalID] { + unclaimedFeeds.append(UnclaimedFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, feedExternalID: feedExternalID)) + self.newUnclaimedFeeds[containerExternalID] = unclaimedFeeds } else { - var unclaimedWebFeeds = [UnclaimedWebFeed]() - unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID)) - self.newUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds + var unclaimedFeeds = [UnclaimedFeed]() + unclaimedFeeds.append(UnclaimedFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, feedExternalID: feedExternalID)) + self.newUnclaimedFeeds[containerExternalID] = unclaimedFeeds } } - func addExistingUnclaimedWebFeed(_ webFeed: WebFeed, containerExternalID: String) { - if var unclaimedWebFeeds = self.existingUnclaimedWebFeeds[containerExternalID] { - unclaimedWebFeeds.append(webFeed) - self.existingUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds + func addExistingUnclaimedFeed(_ feed: Feed, containerExternalID: String) { + if var unclaimedFeeds = self.existingUnclaimedFeeds[containerExternalID] { + unclaimedFeeds.append(feed) + self.existingUnclaimedFeeds[containerExternalID] = unclaimedFeeds } else { - var unclaimedWebFeeds = [WebFeed]() - unclaimedWebFeeds.append(webFeed) - self.existingUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds + var unclaimedFeeds = [Feed]() + unclaimedFeeds.append(feed) + self.existingUnclaimedFeeds[containerExternalID] = unclaimedFeeds } } diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift index c3e68a423..1caa275ad 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZone.swift @@ -29,7 +29,7 @@ final class CloudKitArticlesZone: CloudKitZone { static let recordType = "Article" struct Fields { static let articleStatus = "articleStatus" - static let webFeedURL = "webFeedURL" + static let feedURL = "webFeedURL" static let uniqueID = "uniqueID" static let title = "title" static let contentHTML = "contentHTML" @@ -49,7 +49,7 @@ final class CloudKitArticlesZone: CloudKitZone { struct CloudKitArticleStatus { static let recordType = "ArticleStatus" struct Fields { - static let webFeedExternalID = "webFeedExternalID" + static let feedExternalID = "webFeedExternalID" static let read = "read" static let starred = "starred" } @@ -104,8 +104,8 @@ final class CloudKitArticlesZone: CloudKitZone { } } - func deleteArticles(_ webFeedExternalID: String, completion: @escaping ((Result) -> Void)) { - let predicate = NSPredicate(format: "webFeedExternalID = %@", webFeedExternalID) + func deleteArticles(_ feedExternalID: String, completion: @escaping ((Result) -> Void)) { + let predicate = NSPredicate(format: "webFeedExternalID = %@", feedExternalID) let ckQuery = CKQuery(recordType: CloudKitArticleStatus.recordType, predicate: predicate) delete(ckQuery: ckQuery, completion: completion) } @@ -188,8 +188,8 @@ private extension CloudKitArticlesZone { func makeStatusRecord(_ article: Article) -> CKRecord { let recordID = CKRecord.ID(recordName: statusID(article.articleID), zoneID: zoneID) let record = CKRecord(recordType: CloudKitArticleStatus.recordType, recordID: recordID) - if let webFeedExternalID = article.webFeed?.externalID { - record[CloudKitArticleStatus.Fields.webFeedExternalID] = webFeedExternalID + if let feedExternalID = article.feed?.externalID { + record[CloudKitArticleStatus.Fields.feedExternalID] = feedExternalID } record[CloudKitArticleStatus.Fields.read] = article.status.read ? "1" : "0" record[CloudKitArticleStatus.Fields.starred] = article.status.starred ? "1" : "0" @@ -200,8 +200,8 @@ private extension CloudKitArticlesZone { let recordID = CKRecord.ID(recordName: statusID(statusUpdate.articleID), zoneID: zoneID) let record = CKRecord(recordType: CloudKitArticleStatus.recordType, recordID: recordID) - if let webFeedExternalID = statusUpdate.article?.webFeed?.externalID { - record[CloudKitArticleStatus.Fields.webFeedExternalID] = webFeedExternalID + if let feedExternalID = statusUpdate.article?.feed?.externalID { + record[CloudKitArticleStatus.Fields.feedExternalID] = feedExternalID } record[CloudKitArticleStatus.Fields.read] = statusUpdate.isRead ? "1" : "0" @@ -216,7 +216,7 @@ private extension CloudKitArticlesZone { let articleStatusRecordID = CKRecord.ID(recordName: statusID(article.articleID), zoneID: zoneID) record[CloudKitArticle.Fields.articleStatus] = CKRecord.Reference(recordID: articleStatusRecordID, action: .deleteSelf) - record[CloudKitArticle.Fields.webFeedURL] = article.webFeed?.url + record[CloudKitArticle.Fields.feedURL] = article.feed?.url record[CloudKitArticle.Fields.uniqueID] = article.uniqueID record[CloudKitArticle.Fields.title] = article.title record[CloudKitArticle.Fields.contentHTML] = article.contentHTML diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift index 42bdb591c..a1720f796 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitArticlesZoneDelegate.swift @@ -134,12 +134,12 @@ private extension CloudKitArticlesZoneDelegate { group.enter() compressionQueue.async { let parsedItems = records.compactMap { self.makeParsedItem($0) } - let webFeedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) } - + let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) } + DispatchQueue.main.async { - for (webFeedID, parsedItems) in webFeedIDsAndItems { + for (feedID, parsedItems) in feedIDsAndItems { group.enter() - self.account?.update(webFeedID, with: parsedItems, deleteOlder: false) { result in + self.account?.update(feedID, with: parsedItems, deleteOlder: false) { result in switch result { case .success(let articleChanges): guard let deletes = articleChanges.deletedArticles, !deletes.isEmpty else { @@ -193,7 +193,7 @@ private extension CloudKitArticlesZoneDelegate { } guard let uniqueID = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.uniqueID] as? String, - let webFeedURL = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.webFeedURL] as? String else { + let feedURL = articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.feedURL] as? String else { return nil } @@ -213,7 +213,7 @@ private extension CloudKitArticlesZoneDelegate { let parsedItem = ParsedItem(syncServiceID: nil, uniqueID: uniqueID, - feedURL: webFeedURL, + feedURL: feedURL, url: articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.url] as? String, externalURL: articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.externalURL] as? String, title: articleRecord[CloudKitArticlesZone.CloudKitArticle.Fields.title] as? String, diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift index 4b109c47f..70288dc4d 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift @@ -162,7 +162,7 @@ private extension CloudKitSendStatusOperation { func processAccountError(_ account: Account, _ error: Error) { if case CloudKitZoneError.userDeletedZone = error { - account.removeFeeds(account.topLevelWebFeeds) + account.removeFeeds(account.topLevelFeeds) for folder in account.folders ?? Set() { account.removeFolder(folder) } diff --git a/Modules/Account/Sources/Account/Container.swift b/Modules/Account/Sources/Account/Container.swift index 1a17158ee..a5d1714db 100644 --- a/Modules/Account/Sources/Account/Container.swift +++ b/Modules/Account/Sources/Account/Container.swift @@ -19,27 +19,27 @@ extension Notification.Name { public protocol Container: AnyObject, ContainerIdentifiable { var account: Account? { get } - var topLevelWebFeeds: Set { get set } + var topLevelFeeds: Set { get set } var folders: Set? { get set } var externalID: String? { get set } - func hasAtLeastOneWebFeed() -> Bool + func hasAtLeastOneFeed() -> Bool func objectIsChild(_ object: AnyObject) -> Bool func hasChildFolder(with: String) -> Bool func childFolder(with: String) -> Folder? - func removeWebFeed(_ webFeed: WebFeed) - func addWebFeed(_ webFeed: WebFeed) + func removeFeed(_ feed: Feed) + func addFeed(_ feed: Feed) //Recursive — checks subfolders - func flattenedWebFeeds() -> Set - func has(_ webFeed: WebFeed) -> Bool - func hasWebFeed(with webFeedID: String) -> Bool - func hasWebFeed(withURL url: String) -> Bool - func existingWebFeed(withWebFeedID: String) -> WebFeed? - func existingWebFeed(withURL url: String) -> WebFeed? - func existingWebFeed(withExternalID externalID: String) -> WebFeed? + func flattenedFeeds() -> Set + func has(_ feed: Feed) -> Bool + func hasFeed(with feedID: String) -> Bool + func hasFeed(withURL url: String) -> Bool + func existingFeed(withFeedID: String) -> Feed? + func existingFeed(withURL url: String) -> Feed? + func existingFeed(withExternalID externalID: String) -> Feed? func existingFolder(with name: String) -> Folder? func existingFolder(withID: Int) -> Folder? @@ -48,8 +48,8 @@ public protocol Container: AnyObject, ContainerIdentifiable { public extension Container { - func hasAtLeastOneWebFeed() -> Bool { - return topLevelWebFeeds.count > 0 + func hasAtLeastOneFeed() -> Bool { + return topLevelFeeds.count > 0 } func hasChildFolder(with name: String) -> Bool { @@ -69,8 +69,8 @@ public extension Container { } func objectIsChild(_ object: AnyObject) -> Bool { - if let feed = object as? WebFeed { - return topLevelWebFeeds.contains(feed) + if let feed = object as? Feed { + return topLevelFeeds.contains(feed) } if let folder = object as? Folder { return folders?.contains(folder) ?? false @@ -78,40 +78,40 @@ public extension Container { return false } - func flattenedWebFeeds() -> Set { - var feeds = Set() - feeds.formUnion(topLevelWebFeeds) + func flattenedFeeds() -> Set { + var feeds = Set() + feeds.formUnion(topLevelFeeds) if let folders = folders { for folder in folders { - feeds.formUnion(folder.flattenedWebFeeds()) + feeds.formUnion(folder.flattenedFeeds()) } } return feeds } - func hasWebFeed(with webFeedID: String) -> Bool { - return existingWebFeed(withWebFeedID: webFeedID) != nil + func hasFeed(with feedID: String) -> Bool { + return existingFeed(withFeedID: feedID) != nil } - func hasWebFeed(withURL url: String) -> Bool { - return existingWebFeed(withURL: url) != nil + func hasFeed(withURL url: String) -> Bool { + return existingFeed(withURL: url) != nil } - func has(_ webFeed: WebFeed) -> Bool { - return flattenedWebFeeds().contains(webFeed) + func has(_ feed: Feed) -> Bool { + return flattenedFeeds().contains(feed) } - func existingWebFeed(withWebFeedID webFeedID: String) -> WebFeed? { - for feed in flattenedWebFeeds() { - if feed.webFeedID == webFeedID { + func existingFeed(withFeedID feedID: String) -> Feed? { + for feed in flattenedFeeds() { + if feed.feedID == feedID { return feed } } return nil } - func existingWebFeed(withURL url: String) -> WebFeed? { - for feed in flattenedWebFeeds() { + func existingFeed(withURL url: String) -> Feed? { + for feed in flattenedFeeds() { if feed.url == url { return feed } @@ -119,8 +119,8 @@ public extension Container { return nil } - func existingWebFeed(withExternalID externalID: String) -> WebFeed? { - for feed in flattenedWebFeeds() { + func existingFeed(withExternalID externalID: String) -> Feed? { + for feed in flattenedFeeds() { if feed.externalID == externalID { return feed } diff --git a/Modules/Account/Sources/Account/DataExtensions.swift b/Modules/Account/Sources/Account/DataExtensions.swift index f3b1076ae..3328cb3d0 100644 --- a/Modules/Account/Sources/Account/DataExtensions.swift +++ b/Modules/Account/Sources/Account/DataExtensions.swift @@ -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 { +public extension Feed { - static let WebFeedSettingUserInfoKey = "feedSetting" + static let SettingUserInfoKey = "feedSetting" - struct WebFeedSettingKey { + struct SettingKey { public static let homePageURL = "homePageURL" public static let iconURL = "iconURL" public static let faviconURL = "faviconURL" @@ -31,7 +31,7 @@ public extension WebFeed { } } -extension WebFeed { +extension Feed { func takeSettings(from parsedFeed: ParsedFeed) { iconURL = parsedFeed.iconURL @@ -42,8 +42,8 @@ extension WebFeed { } func postFeedSettingDidChangeNotification(_ codingKey: FeedMetadata.CodingKeys) { - let userInfo = [WebFeed.WebFeedSettingUserInfoKey: codingKey.stringValue] - NotificationCenter.default.post(name: .WebFeedSettingDidChange, object: self, userInfo: userInfo) + let userInfo = [Feed.SettingUserInfoKey: codingKey.stringValue] + NotificationCenter.default.post(name: .feedSettingDidChange, object: self, userInfo: userInfo) } } @@ -57,8 +57,8 @@ public extension Article { return manager.existingAccount(with: accountID) } - var webFeed: WebFeed? { - return account?.existingWebFeed(withWebFeedID: webFeedID) + var feed: Feed? { + return account?.existingFeed(withFeedID: feedID) } } diff --git a/Modules/Account/Sources/Account/WebFeed.swift b/Modules/Account/Sources/Account/Feed.swift similarity index 87% rename from Modules/Account/Sources/Account/WebFeed.swift rename to Modules/Account/Sources/Account/Feed.swift index c7562ea2e..1b073ec10 100644 --- a/Modules/Account/Sources/Account/WebFeed.swift +++ b/Modules/Account/Sources/Account/Feed.swift @@ -1,5 +1,5 @@ // -// WebFeed.swift +// Feed.swift // NetNewsWire // // Created by Brent Simmons on 7/1/17. @@ -11,7 +11,7 @@ import RSCore import RSWeb import Articles -public final class WebFeed: SidebarItem, Renamable, Hashable { +public final class Feed: SidebarItem, Renamable, Hashable { public var defaultReadFilterType: ReadFilterType { return .none @@ -22,18 +22,18 @@ public final class WebFeed: SidebarItem, Renamable, Hashable { assertionFailure("Expected feed.account, but got nil.") return nil } - return SidebarItemIdentifier.webFeed(accountID, webFeedID) + return SidebarItemIdentifier.feed(accountID, feedID) } public weak var account: Account? public let url: String - public var webFeedID: String { + public var feedID: String { get { - return metadata.webFeedID + return metadata.feedID } set { - metadata.webFeedID = newValue + metadata.feedID = newValue } } @@ -222,7 +222,7 @@ public final class WebFeed: SidebarItem, Renamable, Hashable { public func rename(to newName: String, completion: @escaping (Result) -> Void) { guard let account = account else { return } - account.renameWebFeed(self, to: newName, completion: completion) + account.renameFeed(self, to: newName, completion: completion) } // MARK: - UnreadCountProvider @@ -282,19 +282,19 @@ public final class WebFeed: SidebarItem, Renamable, Hashable { // MARK: - Hashable public func hash(into hasher: inout Hasher) { - hasher.combine(webFeedID) + hasher.combine(feedID) } // MARK: - Equatable - public class func ==(lhs: WebFeed, rhs: WebFeed) -> Bool { - return lhs.webFeedID == rhs.webFeedID && lhs.accountID == rhs.accountID + public class func ==(lhs: Feed, rhs: Feed) -> Bool { + return lhs.feedID == rhs.feedID && lhs.accountID == rhs.accountID } } // MARK: - OPMLRepresentable -extension WebFeed: OPMLRepresentable { +extension Feed: OPMLRepresentable { public func OPMLString(indentLevel: Int, allowCustomAttributes: Bool) -> String { // https://github.com/brentsimmons/NetNewsWire/issues/527 @@ -322,18 +322,18 @@ extension WebFeed: OPMLRepresentable { } } -extension Set where Element == WebFeed { +extension Set where Element == Feed { - func webFeedIDs() -> Set { - return Set(map { $0.webFeedID }) + func feedIDs() -> Set { + return Set(map { $0.feedID }) } - func sorted() -> Array { - return sorted(by: { (webFeed1, webFeed2) -> Bool in - if webFeed1.nameForDisplay.localizedStandardCompare(webFeed2.nameForDisplay) == .orderedSame { - return webFeed1.url < webFeed2.url + func sorted() -> Array { + return sorted(by: { (feed1, feed2) -> Bool in + if feed1.nameForDisplay.localizedStandardCompare(feed2.nameForDisplay) == .orderedSame { + return feed1.url < feed2.url } - return webFeed1.nameForDisplay.localizedStandardCompare(webFeed2.nameForDisplay) == .orderedAscending + return feed1.nameForDisplay.localizedStandardCompare(feed2.nameForDisplay) == .orderedAscending }) } diff --git a/Modules/Account/Sources/Account/FeedMetadata.swift b/Modules/Account/Sources/Account/FeedMetadata.swift index e6c6dc53e..98f0d62e8 100644 --- a/Modules/Account/Sources/Account/FeedMetadata.swift +++ b/Modules/Account/Sources/Account/FeedMetadata.swift @@ -17,7 +17,7 @@ protocol FeedMetadataDelegate: AnyObject { final class FeedMetadata: Codable { enum CodingKeys: String, CodingKey { - case webFeedID = "feedID" + case feedID case homePageURL case iconURL case faviconURL @@ -34,10 +34,10 @@ final class FeedMetadata: Codable { case lastCheckDate } - var webFeedID: String { + var feedID: String { didSet { - if webFeedID != oldValue { - valueDidChange(.webFeedID) + if feedID != oldValue { + valueDidChange(.feedID) } } } @@ -164,8 +164,8 @@ final class FeedMetadata: Codable { weak var delegate: FeedMetadataDelegate? - init(webFeedID: String) { - self.webFeedID = webFeedID + init(feedID: String) { + self.feedID = feedID } func valueDidChange(_ key: CodingKeys) { diff --git a/Modules/Account/Sources/Account/FeedMetadataFile.swift b/Modules/Account/Sources/Account/FeedMetadataFile.swift index 07d01f2e5..d45499889 100644 --- a/Modules/Account/Sources/Account/FeedMetadataFile.swift +++ b/Modules/Account/Sources/Account/FeedMetadataFile.swift @@ -71,9 +71,9 @@ private extension FeedMetadataFile { } private func metadataForOnlySubscribedToFeeds() -> Account.FeedMetadataDictionary { - let webFeedIDs = account.idToWebFeedDictionary.keys + let feedIDs = account.idToFeedDictionary.keys return account.feedMetadata.filter { (feedID: String, metadata: FeedMetadata) -> Bool in - return webFeedIDs.contains(metadata.webFeedID) + return feedIDs.contains(metadata.feedID) } } } diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinAPICaller.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinAPICaller.swift index 8ff2028ae..e8e1d8ec1 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinAPICaller.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinAPICaller.swift @@ -357,7 +357,7 @@ final class FeedbinAPICaller: NSObject { } - func createTagging(webFeedID: Int, name: String, completion: @escaping (Result) -> Void) { + func createTagging(feedID: Int, name: String, completion: @escaping (Result) -> Void) { let callURL = feedbinBaseURL.appendingPathComponent("taggings.json") var request = URLRequest(url: callURL, credentials: credentials) @@ -365,7 +365,7 @@ final class FeedbinAPICaller: NSObject { let payload: Data do { - payload = try JSONEncoder().encode(FeedbinCreateTagging(feedID: webFeedID, name: name)) + payload = try JSONEncoder().encode(FeedbinCreateTagging(feedID: feedID, name: name)) } catch { completion(.failure(error)) return diff --git a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 6e297c4d0..8e4c59cb3 100644 --- a/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -301,7 +301,7 @@ final class FeedbinAccountDelegate: AccountDelegate { func renameFolder(for account: Account, with folder: Folder, to name: String, completion: @escaping (Result) -> Void) { - guard folder.hasAtLeastOneWebFeed() else { + guard folder.hasAtLeastOneFeed() else { folder.name = name return } @@ -329,7 +329,7 @@ final class FeedbinAccountDelegate: AccountDelegate { func removeFolder(for account: Account, with folder: Folder, completion: @escaping (Result) -> Void) { // Feedbin uses tags and if at least one feed isn't tagged, then the folder doesn't exist on their system - guard folder.hasAtLeastOneWebFeed() else { + guard folder.hasAtLeastOneFeed() else { account.removeFolder(folder) completion(.success(())) return @@ -337,7 +337,7 @@ final class FeedbinAccountDelegate: AccountDelegate { let group = DispatchGroup() - for feed in folder.topLevelWebFeeds { + for feed in folder.topLevelFeeds { if feed.folderRelationship?.count ?? 0 > 1 { @@ -389,7 +389,7 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func createWebFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { + func createFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { refreshProgress.addToNumberOfTasksAndRemaining(1) caller.createSubscription(url: url) { result in @@ -421,7 +421,7 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result) -> Void) { + func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { // This error should never happen guard let subscriptionID = feed.externalID else { @@ -448,7 +448,7 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result) -> Void) { + func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { if feed.folderRelationship?.count ?? 0 > 1 { deleteTagging(for: account, with: feed, from: container, completion: completion) } else { @@ -456,14 +456,14 @@ final class FeedbinAccountDelegate: AccountDelegate { } } - func moveWebFeed(for account: Account, with feed: WebFeed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { if from is Account { - addWebFeed(for: account, with: feed, to: to, completion: completion) + addFeed(for: account, with: feed, to: to, completion: completion) } else { deleteTagging(for: account, with: feed, from: from) { result in switch result { case .success: - self.addWebFeed(for: account, with: feed, to: to, completion: completion) + self.addFeed(for: account, with: feed, to: to, completion: completion) case .failure(let error): completion(.failure(error)) } @@ -471,18 +471,18 @@ final class FeedbinAccountDelegate: AccountDelegate { } } - func addWebFeed(for account: Account, with feed: WebFeed, to container: Container, completion: @escaping (Result) -> Void) { + func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result) -> Void) { - if let folder = container as? Folder, let webFeedID = Int(feed.webFeedID) { + if let folder = container as? Folder, let feedID = Int(feed.feedID) { refreshProgress.addToNumberOfTasksAndRemaining(1) - caller.createTagging(webFeedID: webFeedID, name: folder.name ?? "") { result in + caller.createTagging(feedID: feedID, name: folder.name ?? "") { result in self.refreshProgress.completeTask() switch result { case .success(let taggingID): DispatchQueue.main.async { self.saveFolderRelationship(for: feed, withFolderName: folder.name ?? "", id: String(taggingID)) - account.removeWebFeed(feed) - folder.addWebFeed(feed) + account.removeFeed(feed) + folder.addFeed(feed) completion(.success(())) } case .failure(let error): @@ -503,10 +503,10 @@ final class FeedbinAccountDelegate: AccountDelegate { } - func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result) -> Void) { + func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result) -> Void) { - if let existingFeed = account.existingWebFeed(withURL: feed.url) { - account.addWebFeed(existingFeed, to: container) { result in + if let existingFeed = account.existingFeed(withURL: feed.url) { + account.addFeed(existingFeed, to: container) { result in switch result { case .success: completion(.success(())) @@ -515,7 +515,7 @@ final class FeedbinAccountDelegate: AccountDelegate { } } } else { - createWebFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in + createFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in switch result { case .success: completion(.success(())) @@ -531,12 +531,12 @@ final class FeedbinAccountDelegate: AccountDelegate { let group = DispatchGroup() - for feed in folder.topLevelWebFeeds { + for feed in folder.topLevelFeeds { - folder.topLevelWebFeeds.remove(feed) + folder.topLevelFeeds.remove(feed) group.enter() - restoreWebFeed(for: account, feed: feed, container: folder) { result in + restoreFeed(for: account, feed: feed, container: folder) { result in group.leave() switch result { case .success: @@ -781,8 +781,8 @@ private extension FeedbinAccountDelegate { if let folders = account.folders { folders.forEach { folder in if !tagNames.contains(folder.name ?? "") { - for feed in folder.topLevelWebFeeds { - account.addWebFeed(feed) + for feed in folder.topLevelFeeds { + account.addFeed(feed) clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") } account.removeFolder(folder) @@ -819,17 +819,17 @@ private extension FeedbinAccountDelegate { // Remove any feeds that are no longer in the subscriptions if let folders = account.folders { for folder in folders { - for feed in folder.topLevelWebFeeds { - if !subFeedIds.contains(feed.webFeedID) { - folder.removeWebFeed(feed) + for feed in folder.topLevelFeeds { + if !subFeedIds.contains(feed.feedID) { + folder.removeFeed(feed) } } } } - for feed in account.topLevelWebFeeds { - if !subFeedIds.contains(feed.webFeedID) { - account.removeWebFeed(feed) + for feed in account.topLevelFeeds { + if !subFeedIds.contains(feed.feedID) { + account.removeFeed(feed) } } @@ -839,7 +839,7 @@ private extension FeedbinAccountDelegate { let subFeedId = String(subscription.feedID) - if let feed = account.existingWebFeed(withWebFeedID: subFeedId) { + if let feed = account.existingFeed(withFeedID: subFeedId) { feed.name = subscription.name // If the name has been changed on the server remove the locally edited name feed.editedName = nil @@ -855,9 +855,9 @@ private extension FeedbinAccountDelegate { // Actually add subscriptions all in one go, so we don’t trigger various rebuilding things that Account does. subscriptionsToAdd.forEach { subscription in - let feed = account.createWebFeed(with: subscription.name, url: subscription.url, webFeedID: String(subscription.feedID), homePageURL: subscription.homePageURL) + let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: String(subscription.feedID), homePageURL: subscription.homePageURL) feed.externalID = String(subscription.subscriptionID) - account.addWebFeed(feed) + account.addFeed(feed) } } @@ -889,25 +889,25 @@ private extension FeedbinAccountDelegate { let taggingFeedIDs = groupedTaggings.map { String($0.feedID) } // Move any feeds not in the folder to the account - for feed in folder.topLevelWebFeeds { - if !taggingFeedIDs.contains(feed.webFeedID) { - folder.removeWebFeed(feed) + for feed in folder.topLevelFeeds { + if !taggingFeedIDs.contains(feed.feedID) { + folder.removeFeed(feed) clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") - account.addWebFeed(feed) + account.addFeed(feed) } } // Add any feeds not in the folder - let folderFeedIds = folder.topLevelWebFeeds.map { $0.webFeedID } + let folderFeedIds = folder.topLevelFeeds.map { $0.feedID } for tagging in groupedTaggings { let taggingFeedID = String(tagging.feedID) if !folderFeedIds.contains(taggingFeedID) { - guard let feed = account.existingWebFeed(withWebFeedID: taggingFeedID) else { + guard let feed = account.existingFeed(withFeedID: taggingFeedID) else { continue } saveFolderRelationship(for: feed, withFolderName: folderName, id: String(tagging.taggingID)) - folder.addWebFeed(feed) + folder.addFeed(feed) } } @@ -916,9 +916,9 @@ private extension FeedbinAccountDelegate { let taggedFeedIDs = Set(taggings.map { String($0.feedID) }) // Remove all feeds from the account container that have a tag - for feed in account.topLevelWebFeeds { - if taggedFeedIDs.contains(feed.webFeedID) { - account.removeWebFeed(feed) + for feed in account.topLevelFeeds { + if taggedFeedIDs.contains(feed.feedID) { + account.removeFeed(feed) } } } @@ -982,7 +982,7 @@ private extension FeedbinAccountDelegate { } func renameFolderRelationship(for account: Account, fromName: String, toName: String) { - for feed in account.flattenedWebFeeds() { + for feed in account.flattenedFeeds() { if var folderRelationship = feed.folderRelationship { let relationship = folderRelationship[fromName] folderRelationship[fromName] = nil @@ -992,14 +992,14 @@ private extension FeedbinAccountDelegate { } } - func clearFolderRelationship(for feed: WebFeed, withFolderName folderName: String) { + func clearFolderRelationship(for feed: Feed, withFolderName folderName: String) { if var folderRelationship = feed.folderRelationship { folderRelationship[folderName] = nil feed.folderRelationship = folderRelationship } } - func saveFolderRelationship(for feed: WebFeed, withFolderName folderName: String, id: String) { + func saveFolderRelationship(for feed: Feed, withFolderName folderName: String, id: String) { if var folderRelationship = feed.folderRelationship { folderRelationship[folderName] = id feed.folderRelationship = folderRelationship @@ -1008,7 +1008,7 @@ private extension FeedbinAccountDelegate { } } - func decideBestFeedChoice(account: Account, url: String, name: String?, container: Container, choices: [FeedbinSubscriptionChoice], completion: @escaping (Result) -> Void) { + func decideBestFeedChoice(account: Account, url: String, name: String?, container: Container, choices: [FeedbinSubscriptionChoice], completion: @escaping (Result) -> Void) { var orderFound = 0 let feedSpecifiers: [FeedSpecifier] = choices.map { choice in @@ -1019,7 +1019,7 @@ private extension FeedbinAccountDelegate { } if let bestSpecifier = FeedSpecifier.bestFeed(in: Set(feedSpecifiers)) { - createWebFeed(for: account, url: bestSpecifier.urlString, name: name, container: container, validateFeed: true, completion: completion) + createFeed(for: account, url: bestSpecifier.urlString, name: name, container: container, validateFeed: true, completion: completion) } else { DispatchQueue.main.async { completion(.failure(FeedbinAccountDelegateError.invalidParameter)) @@ -1027,20 +1027,20 @@ private extension FeedbinAccountDelegate { } } - func createFeed( account: Account, subscription sub: FeedbinSubscription, name: String?, container: Container, completion: @escaping (Result) -> Void) { + func createFeed( account: Account, subscription sub: FeedbinSubscription, name: String?, container: Container, completion: @escaping (Result) -> Void) { DispatchQueue.main.async { - let feed = account.createWebFeed(with: sub.name, url: sub.url, webFeedID: String(sub.feedID), homePageURL: sub.homePageURL) + let feed = account.createFeed(with: sub.name, url: sub.url, feedID: String(sub.feedID), homePageURL: sub.homePageURL) feed.externalID = String(sub.subscriptionID) feed.iconURL = sub.jsonFeed?.icon feed.faviconURL = sub.jsonFeed?.favicon - account.addWebFeed(feed, to: container) { result in + account.addFeed(feed, to: container) { result in switch result { case .success: if let name = name { - account.renameWebFeed(feed, to: name) { result in + account.renameFeed(feed, to: name) { result in switch result { case .success: self.initialFeedDownload(account: account, feed: feed, completion: completion) @@ -1060,13 +1060,13 @@ private extension FeedbinAccountDelegate { } - func initialFeedDownload( account: Account, feed: WebFeed, completion: @escaping (Result) -> Void) { + func initialFeedDownload( account: Account, feed: Feed, completion: @escaping (Result) -> Void) { // refreshArticles is being reused and will clear one of the tasks for us refreshProgress.addToNumberOfTasksAndRemaining(4) // Download the initial articles - self.caller.retrieveEntries(feedID: feed.webFeedID) { result in + self.caller.retrieveEntries(feedID: feed.feedID) { result in self.refreshProgress.completeTask() switch result { @@ -1250,8 +1250,8 @@ private extension FeedbinAccountDelegate { func processEntries(account: Account, entries: [FeedbinEntry]?, completion: @escaping DatabaseCompletionBlock) { let parsedItems = mapEntriesToParsedItems(entries: entries) - let webFeedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) } - account.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: true, completion: completion) + let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) } + account.update(feedIDsAndItems: feedIDsAndItems, defaultRead: true, completion: completion) } func mapEntriesToParsedItems(entries: [FeedbinEntry]?) -> Set { @@ -1369,7 +1369,7 @@ private extension FeedbinAccountDelegate { } } - func deleteTagging(for account: Account, with feed: WebFeed, from container: Container?, completion: @escaping (Result) -> Void) { + func deleteTagging(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result) -> Void) { if let folder = container as? Folder, let feedTaggingID = feed.folderRelationship?[folder.name ?? ""] { refreshProgress.addToNumberOfTasksAndRemaining(1) @@ -1379,7 +1379,7 @@ private extension FeedbinAccountDelegate { case .success: DispatchQueue.main.async { self.clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") - folder.removeWebFeed(feed) + folder.removeFeed(feed) account.addFeedIfNotInAnyFolder(feed) completion(.success(())) } @@ -1392,14 +1392,14 @@ private extension FeedbinAccountDelegate { } } else { if let account = container as? Account { - account.removeWebFeed(feed) + account.removeFeed(feed) } completion(.success(())) } } - func deleteSubscription(for account: Account, with feed: WebFeed, from container: Container?, completion: @escaping (Result) -> Void) { + func deleteSubscription(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result) -> Void) { // This error should never happen guard let subscriptionID = feed.externalID else { @@ -1410,10 +1410,10 @@ private extension FeedbinAccountDelegate { func complete() { DispatchQueue.main.async { account.clearFeedMetadata(feed) - account.removeWebFeed(feed) + account.removeFeed(feed) if let folders = account.folders { for folder in folders { - folder.removeWebFeed(feed) + folder.removeFeed(feed) } } completion(.success(())) diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index cd7300c4c..360fd2238 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -320,7 +320,7 @@ final class FeedlyAccountDelegate: AccountDelegate { } } - func createWebFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { + func createFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { do { guard let credentials = credentials else { @@ -352,14 +352,14 @@ final class FeedlyAccountDelegate: AccountDelegate { } } - func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result) -> Void) { + func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { let folderCollectionIds = account.folders?.filter { $0.has(feed) }.compactMap { $0.externalID } guard let collectionIds = folderCollectionIds, let collectionId = collectionIds.first else { completion(.failure(FeedlyAccountDelegateError.unableToRenameFeed(feed.nameForDisplay, name))) return } - let feedId = FeedlyFeedResourceId(id: feed.webFeedID) + let feedId = FeedlyFeedResourceId(id: feed.feedID) let editedNameBefore = feed.editedName // Adding an existing feed updates it. @@ -379,14 +379,14 @@ final class FeedlyAccountDelegate: AccountDelegate { feed.editedName = name } - func addWebFeed(for account: Account, with feed: WebFeed, to container: Container, completion: @escaping (Result) -> Void) { + func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result) -> Void) { do { guard let credentials = credentials else { throw FeedlyAccountDelegateError.notLoggedIn } - let resource = FeedlyFeedResourceId(id: feed.webFeedID) + let resource = FeedlyFeedResourceId(id: feed.feedID) let addExistingFeed = try FeedlyAddExistingFeedOperation(account: account, credentials: credentials, resource: resource, @@ -409,62 +409,62 @@ final class FeedlyAccountDelegate: AccountDelegate { } } - func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result) -> Void) { + func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { guard let folder = container as? Folder, let collectionId = folder.externalID else { return DispatchQueue.main.async { completion(.failure(FeedlyAccountDelegateError.unableToRemoveFeed(feed))) } } - caller.removeFeed(feed.webFeedID, fromCollectionWith: collectionId) { result in + caller.removeFeed(feed.feedID, fromCollectionWith: collectionId) { result in switch result { case .success: completion(.success(())) case .failure(let error): - folder.addWebFeed(feed) + folder.addFeed(feed) completion(.failure(error)) } } - folder.removeWebFeed(feed) + folder.removeFeed(feed) } - func moveWebFeed(for account: Account, with feed: WebFeed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { guard let from = from as? Folder, let to = to as? Folder else { return DispatchQueue.main.async { completion(.failure(FeedlyAccountDelegateError.addFeedChooseFolder)) } } - addWebFeed(for: account, with: feed, to: to) { [weak self] addResult in + addFeed(for: account, with: feed, to: to) { [weak self] addResult in switch addResult { // now that we have added the feed, remove it from the other collection case .success: - self?.removeWebFeed(for: account, with: feed, from: from) { removeResult in + self?.removeFeed(for: account, with: feed, from: from) { removeResult in switch removeResult { case .success: completion(.success(())) case .failure: - from.addWebFeed(feed) + from.addFeed(feed) completion(.failure(FeedlyAccountDelegateError.unableToMoveFeedBetweenFolders(feed, from, to))) } } case .failure(let error): - from.addWebFeed(feed) - to.removeWebFeed(feed) + from.addFeed(feed) + to.removeFeed(feed) completion(.failure(error)) } } // optimistically move the feed, undoing as appropriate to the failure - from.removeWebFeed(feed) - to.addWebFeed(feed) + from.removeFeed(feed) + to.addFeed(feed) } - func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result) -> Void) { - if let existingFeed = account.existingWebFeed(withURL: feed.url) { - account.addWebFeed(existingFeed, to: container) { result in + func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result) -> Void) { + if let existingFeed = account.existingFeed(withURL: feed.url) { + account.addFeed(existingFeed, to: container) { result in switch result { case .success: completion(.success(())) @@ -473,7 +473,7 @@ final class FeedlyAccountDelegate: AccountDelegate { } } } else { - createWebFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in + createFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in switch result { case .success: completion(.success(())) @@ -487,12 +487,12 @@ final class FeedlyAccountDelegate: AccountDelegate { func restoreFolder(for account: Account, folder: Folder, completion: @escaping (Result) -> Void) { let group = DispatchGroup() - for feed in folder.topLevelWebFeeds { + for feed in folder.topLevelFeeds { - folder.topLevelWebFeeds.remove(feed) + folder.topLevelFeeds.remove(feed) group.enter() - restoreWebFeed(for: account, feed: feed, container: folder) { result in + restoreFeed(for: account, feed: feed, container: folder) { result in group.leave() switch result { case .success: diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegateError.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegateError.swift index 3c7a42ef9..0ed5cac99 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegateError.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegateError.swift @@ -14,11 +14,11 @@ enum FeedlyAccountDelegateError: LocalizedError { case unableToAddFolder(String) case unableToRenameFolder(String, String) case unableToRemoveFolder(String) - case unableToMoveFeedBetweenFolders(WebFeed, Folder, Folder) + case unableToMoveFeedBetweenFolders(Feed, Folder, Folder) case addFeedChooseFolder case addFeedInvalidFolder(Folder) case unableToRenameFeed(String, String) - case unableToRemoveFeed(WebFeed) + case unableToRemoveFeed(Feed) var errorDescription: String? { switch self { diff --git a/Modules/Account/Sources/Account/Feedly/Models/FeedlyEntryParser.swift b/Modules/Account/Sources/Account/Feedly/Models/FeedlyEntryParser.swift index b2a197a8a..51b5aa913 100644 --- a/Modules/Account/Sources/Account/Feedly/Models/FeedlyEntryParser.swift +++ b/Modules/Account/Sources/Account/Feedly/Models/FeedlyEntryParser.swift @@ -19,7 +19,7 @@ struct FeedlyEntryParser { return entry.id } - /// When ingesting articles, the feedURL must match a feed's `webFeedID` for the article to be reachable between it and its matching feed. It reminds me of a foreign key. + /// When ingesting articles, the feedURL must match a feed's `feedID` for the article to be reachable between it and its matching feed. It reminds me of a foreign key. var feedUrl: String? { guard let id = entry.origin?.streamId else { // At this point, check Feedly's API isn't glitching or the response has not changed structure. diff --git a/Modules/Account/Sources/Account/Feedly/Models/FeedlyFeedParser.swift b/Modules/Account/Sources/Account/Feedly/Models/FeedlyFeedParser.swift index e2f288dce..a9faf3f25 100644 --- a/Modules/Account/Sources/Account/Feedly/Models/FeedlyFeedParser.swift +++ b/Modules/Account/Sources/Account/Feedly/Models/FeedlyFeedParser.swift @@ -17,7 +17,7 @@ struct FeedlyFeedParser { return rightToLeftTextSantizer.sanitize(feed.title) ?? "" } - var webFeedID: String { + var feedID: String { return feed.id } diff --git a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyAddNewFeedOperation.swift b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyAddNewFeedOperation.swift index 0ef9253d8..de99cc228 100644 --- a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyAddNewFeedOperation.swift +++ b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyAddNewFeedOperation.swift @@ -27,7 +27,7 @@ final class FeedlyAddNewFeedOperation: FeedlyOperation, FeedlyOperationDelegate, private let syncUnreadIdsService: FeedlyGetStreamIdsService private let getStreamContentsService: FeedlyGetStreamContentsService private var feedResourceId: FeedlyFeedResourceId? - var addCompletionHandler: ((Result) -> ())? + var addCompletionHandler: ((Result) -> ())? init(account: Account, credentials: Credentials, url: String, feedName: String?, searchService: FeedlySearchService, addToCollectionService: FeedlyAddFeedToCollectionService, syncUnreadIdsService: FeedlyGetStreamIdsService, getStreamContentsService: FeedlyGetStreamContentsService, database: SyncDatabase, container: Container, progress: DownloadProgress) throws { @@ -135,7 +135,7 @@ final class FeedlyAddNewFeedOperation: FeedlyOperation, FeedlyOperationDelegate, guard let handler = addCompletionHandler else { return } - if let feedResource = feedResourceId, let feed = folder.existingWebFeed(withWebFeedID: feedResource.id) { + if let feedResource = feedResourceId, let feed = folder.existingFeed(withFeedID: feedResource.id) { handler(.success(feed)) } else { diff --git a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyCreateFeedsForCollectionFoldersOperation.swift b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyCreateFeedsForCollectionFoldersOperation.swift index c5486152c..08d4e6110 100644 --- a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyCreateFeedsForCollectionFoldersOperation.swift +++ b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyCreateFeedsForCollectionFoldersOperation.swift @@ -29,13 +29,13 @@ final class FeedlyCreateFeedsForCollectionFoldersOperation: FeedlyOperation { let feedsBefore = Set(pairs .map { $0.1 } - .flatMap { $0.topLevelWebFeeds }) + .flatMap { $0.topLevelFeeds }) // Remove feeds in a folder which are not in the corresponding collection. for (collectionFeeds, folder) in pairs { - let feedsInFolder = folder.topLevelWebFeeds + let feedsInFolder = folder.topLevelFeeds let feedsInCollection = Set(collectionFeeds.map { $0.id }) - let feedsToRemove = feedsInFolder.filter { !feedsInCollection.contains($0.webFeedID) } + let feedsToRemove = feedsInFolder.filter { !feedsInCollection.contains($0.feedID) } if !feedsToRemove.isEmpty { folder.removeFeeds(feedsToRemove) // os_log(.debug, log: log, "\"%@\" - removed: %@", collection.label, feedsToRemove.map { $0.feedID }, feedsInCollection) @@ -44,7 +44,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperation: FeedlyOperation { } // Pair each Feed with its Folder. - var feedsAdded = Set() + var feedsAdded = Set() let feedsAndFolders = pairs .map({ (collectionFeeds, folder) -> [(FeedlyFeed, Folder)] in @@ -53,10 +53,10 @@ final class FeedlyCreateFeedsForCollectionFoldersOperation: FeedlyOperation { } }) .flatMap { $0 } - .compactMap { (collectionFeed, folder) -> (WebFeed, Folder) in + .compactMap { (collectionFeed, folder) -> (Feed, Folder) in // find an existing feed previously added to the account - if let feed = account.existingWebFeed(withWebFeedID: collectionFeed.id) { + if let feed = account.existingFeed(withFeedID: collectionFeed.id) { // If the feed was renamed on Feedly, ensure we ingest the new name. if feed.nameForDisplay != collectionFeed.title { @@ -74,16 +74,16 @@ final class FeedlyCreateFeedsForCollectionFoldersOperation: FeedlyOperation { return (feed, folder) } else { // find an existing feed we created below in an earlier value - for feed in feedsAdded where feed.webFeedID == collectionFeed.id { + for feed in feedsAdded where feed.feedID == collectionFeed.id { return (feed, folder) } } // no existing feed, create a new one let parser = FeedlyFeedParser(feed: collectionFeed) - let feed = account.createWebFeed(with: parser.title, + let feed = account.createFeed(with: parser.title, url: parser.url, - webFeedID: parser.webFeedID, + feedID: parser.feedID, homePageURL: parser.homePageURL) // So the same feed isn't created more than once. @@ -95,7 +95,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperation: FeedlyOperation { Feedly.logger.info("Feedly: Processing \(feedsAndFolders.count) feeds") feedsAndFolders.forEach { (feed, folder) in if !folder.has(feed) { - folder.addWebFeed(feed) + folder.addFeed(feed) } } diff --git a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyUpdateAccountFeedsWithItemsOperation.swift b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyUpdateAccountFeedsWithItemsOperation.swift index c26359f22..eb553e741 100644 --- a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyUpdateAccountFeedsWithItemsOperation.swift +++ b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyUpdateAccountFeedsWithItemsOperation.swift @@ -22,15 +22,15 @@ final class FeedlyUpdateAccountFeedsWithItemsOperation: FeedlyOperation { } override func run() { - let webFeedIDsAndItems = organisedItemsProvider.parsedItemsKeyedByFeedId + let feedIDsAndItems = organisedItemsProvider.parsedItemsKeyedByFeedId - account.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: true) { databaseError in + account.update(feedIDsAndItems: feedIDsAndItems, defaultRead: true) { databaseError in if let error = databaseError { self.didFinish(with: error) return } - Feedly.logger.info("Feedly: updated \(webFeedIDsAndItems.count) for \(self.organisedItemsProvider.parsedItemsByFeedProviderName)") + Feedly.logger.info("Feedly: updated \(feedIDsAndItems.count) for \(self.organisedItemsProvider.parsedItemsByFeedProviderName)") self.didFinish() } } diff --git a/Modules/Account/Sources/Account/Folder.swift b/Modules/Account/Sources/Account/Folder.swift index 07bb8c8cc..f088e3a26 100644 --- a/Modules/Account/Sources/Account/Folder.swift +++ b/Modules/Account/Sources/Account/Folder.swift @@ -33,7 +33,7 @@ public final class Folder: SidebarItem, Renamable, Container, Hashable { } public weak var account: Account? - public var topLevelWebFeeds: Set = Set() + public var topLevelFeeds: Set = Set() public var folders: Set? = nil // subfolders are not supported, so this is always nil public var name: String? { @@ -100,42 +100,42 @@ public final class Folder: SidebarItem, Renamable, Container, Hashable { // MARK: Container - public func flattenedWebFeeds() -> Set { + public func flattenedFeeds() -> Set { // Since sub-folders are not supported, it’s always the top-level feeds. - return topLevelWebFeeds + return topLevelFeeds } public func objectIsChild(_ object: AnyObject) -> Bool { // Folders contain Feed objects only, at least for now. - guard let feed = object as? WebFeed else { + guard let feed = object as? Feed else { return false } - return topLevelWebFeeds.contains(feed) + return topLevelFeeds.contains(feed) } - public func addWebFeed(_ feed: WebFeed) { - topLevelWebFeeds.insert(feed) + public func addFeed(_ feed: Feed) { + topLevelFeeds.insert(feed) postChildrenDidChangeNotification() } - public func addFeeds(_ feeds: Set) { + public func addFeeds(_ feeds: Set) { guard !feeds.isEmpty else { return } - topLevelWebFeeds.formUnion(feeds) + topLevelFeeds.formUnion(feeds) postChildrenDidChangeNotification() } - public func removeWebFeed(_ feed: WebFeed) { - topLevelWebFeeds.remove(feed) + public func removeFeed(_ feed: Feed) { + topLevelFeeds.remove(feed) postChildrenDidChangeNotification() } - public func removeFeeds(_ feeds: Set) { + public func removeFeeds(_ feeds: Set) { guard !feeds.isEmpty else { return } - topLevelWebFeeds.subtract(feeds) + topLevelFeeds.subtract(feeds) postChildrenDidChangeNotification() } @@ -158,14 +158,14 @@ private extension Folder { func updateUnreadCount() { var updatedUnreadCount = 0 - for feed in topLevelWebFeeds { + for feed in topLevelFeeds { updatedUnreadCount += feed.unreadCount } unreadCount = updatedUnreadCount } - func childrenContain(_ feed: WebFeed) -> Bool { - return topLevelWebFeeds.contains(feed) + func childrenContain(_ feed: Feed) -> Bool { + return topLevelFeeds.contains(feed) } } @@ -189,7 +189,7 @@ extension Folder: OPMLRepresentable { var hasAtLeastOneChild = false - for feed in topLevelWebFeeds.sorted() { + for feed in topLevelFeeds.sorted() { s += feed.OPMLString(indentLevel: indentLevel + 1, allowCustomAttributes: allowCustomAttributes) hasAtLeastOneChild = true } diff --git a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 6a2f292e1..0709b5cca 100644 --- a/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Modules/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -49,12 +49,12 @@ final class LocalAccountDelegate: AccountDelegate { return } - let webFeeds = account.flattenedWebFeeds() + let feeds = account.flattenedFeeds() let group = DispatchGroup() group.enter() - refresher.refreshFeeds(webFeeds) { + refresher.refreshFeeds(feeds) { group.leave() } @@ -117,38 +117,38 @@ final class LocalAccountDelegate: AccountDelegate { completion(.success(())) } - func createWebFeed(for account: Account, url urlString: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { + func createFeed(for account: Account, url urlString: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { guard let url = URL(string: urlString) else { completion(.failure(LocalAccountDelegateError.invalidParameter)) return } - createRSSWebFeed(for: account, url: url, editedName: name, container: container, completion: completion) + createFeed(for: account, url: url, editedName: name, container: container, completion: completion) } - func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result) -> Void) { + func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { feed.editedName = name completion(.success(())) } - func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result) -> Void) { - container.removeWebFeed(feed) + func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { + container.removeFeed(feed) completion(.success(())) } - func moveWebFeed(for account: Account, with feed: WebFeed, from: Container, to: Container, completion: @escaping (Result) -> Void) { - from.removeWebFeed(feed) - to.addWebFeed(feed) + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + from.removeFeed(feed) + to.addFeed(feed) completion(.success(())) } - func addWebFeed(for account: Account, with feed: WebFeed, to container: Container, completion: @escaping (Result) -> Void) { - container.addWebFeed(feed) + func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result) -> Void) { + container.addFeed(feed) completion(.success(())) } - func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result) -> Void) { - container.addWebFeed(feed) + func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result) -> Void) { + container.addFeed(feed) completion(.success(())) } @@ -219,7 +219,7 @@ extension LocalAccountDelegate: LocalAccountRefresherDelegate { private extension LocalAccountDelegate { - func createRSSWebFeed(for account: Account, url: URL, editedName: String?, container: Container, completion: @escaping (Result) -> Void) { + func createFeed(for account: Account, url: URL, editedName: String?, container: Container, completion: @escaping (Result) -> Void) { // We need to use a batch update here because we need to assign add the feed to the // container before the name has been downloaded. This will put it in the sidebar @@ -236,7 +236,7 @@ private extension LocalAccountDelegate { return } - if account.hasWebFeed(withURL: bestFeedSpecifier.urlString) { + if account.hasFeed(withURL: bestFeedSpecifier.urlString) { BatchUpdate.shared.end() completion(.failure(AccountError.createErrorAlreadySubscribed)) return @@ -245,7 +245,7 @@ private extension LocalAccountDelegate { InitialFeedDownloader.download(url) { parsedFeed, _, response, _ in if let parsedFeed { - let feed = account.createWebFeed(with: nil, url: url.absoluteString, webFeedID: url.absoluteString, homePageURL: nil) + let feed = account.createFeed(with: nil, url: url.absoluteString, feedID: url.absoluteString, homePageURL: nil) feed.lastCheckDate = Date() // Save conditional GET info so that first refresh uses conditional GET. @@ -255,7 +255,7 @@ private extension LocalAccountDelegate { } feed.editedName = editedName - container.addWebFeed(feed) + container.addFeed(feed) account.update(feed, with: parsedFeed, {_ in BatchUpdate.shared.end() diff --git a/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift b/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift index e449cd84e..b72dc53c1 100644 --- a/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift +++ b/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift @@ -32,11 +32,11 @@ final class LocalAccountRefresher { return DownloadSession(delegate: self) }() - private var urlToFeedDictionary = [String: WebFeed]() + private var urlToFeedDictionary = [String: Feed]() private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "LocalAccountRefresher") - public func refreshFeeds(_ feeds: Set, completion: (() -> Void)? = nil) { + public func refreshFeeds(_ feeds: Set, completion: (() -> Void)? = nil) { let specialCaseCutoffDate = Date().bySubtracting(hours: 25) let filteredFeeds = feeds.filter { !Self.feedShouldBeSkipped($0, specialCaseCutoffDate) } @@ -197,7 +197,7 @@ private extension LocalAccountRefresher { static let badHosts = ["twitter.com", "www.twitter.com", "x.com", "www.x.com"] /// Return true if we won’t download that feed. - static func feedIsDisallowed(_ feed: WebFeed) -> Bool { + static func feedIsDisallowed(_ feed: Feed) -> Bool { guard let url = url(for: feed) else { return true @@ -216,13 +216,13 @@ private extension LocalAccountRefresher { return false } - static func feedShouldBeSkipped(_ feed: WebFeed, _ specialCaseCutoffDate: Date) -> Bool { + static func feedShouldBeSkipped(_ feed: Feed, _ specialCaseCutoffDate: Date) -> Bool { feedShouldBeSkippedForCacheControlReasons(feed) || feedIsDisallowed(feed) || feedShouldBeSkippedForTimingReasons(feed, specialCaseCutoffDate) } - static func feedShouldBeSkippedForTimingReasons(_ feed: WebFeed, _ specialCaseCutoffDate: Date) -> Bool { + static func feedShouldBeSkippedForTimingReasons(_ feed: Feed, _ specialCaseCutoffDate: Date) -> Bool { guard let lastCheckDate = feed.lastCheckDate else { return false } @@ -237,7 +237,7 @@ private extension LocalAccountRefresher { return false } - static func feedShouldBeSkippedForCacheControlReasons(_ feed: WebFeed) -> Bool { + static func feedShouldBeSkippedForCacheControlReasons(_ feed: Feed) -> Bool { // We support Cache-Control only for openrss.org. The rest of the feed-providing // universe hasn’t dealt with Cache-Control, and we routinely see days-long // max-ages for even fast-moving feeds. @@ -256,7 +256,7 @@ private extension LocalAccountRefresher { static var urlCache = [String: URL]() - static func url(for feed: WebFeed) -> URL? { + static func url(for feed: Feed) -> URL? { assert(Thread.isMainThread) diff --git a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift index c244fd155..0c75b13e9 100644 --- a/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift +++ b/Modules/Account/Sources/Account/NewsBlur/Internals/NewsBlurAccountDelegate+Internal.swift @@ -47,8 +47,8 @@ extension NewsBlurAccountDelegate { if let folders = account.folders { folders.forEach { folder in if !folderNames.contains(folder.name ?? "") { - for feed in folder.topLevelWebFeeds { - account.addWebFeed(feed) + for feed in folder.topLevelFeeds { + account.addFeed(feed) clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") } account.removeFolder(folder) @@ -84,17 +84,17 @@ extension NewsBlurAccountDelegate { // Remove any feeds that are no longer in the subscriptions if let folders = account.folders { for folder in folders { - for feed in folder.topLevelWebFeeds { - if !newsBlurFeedIds.contains(feed.webFeedID) { - folder.removeWebFeed(feed) + for feed in folder.topLevelFeeds { + if !newsBlurFeedIds.contains(feed.feedID) { + folder.removeFeed(feed) } } } } - for feed in account.topLevelWebFeeds { - if !newsBlurFeedIds.contains(feed.webFeedID) { - account.removeWebFeed(feed) + for feed in account.topLevelFeeds { + if !newsBlurFeedIds.contains(feed.feedID) { + account.removeFeed(feed) } } @@ -103,13 +103,13 @@ extension NewsBlurAccountDelegate { feeds.forEach { feed in let subFeedId = String(feed.feedID) - if let webFeed = account.existingWebFeed(withWebFeedID: subFeedId) { - webFeed.name = feed.name + if let feed = account.existingFeed(withFeedID: subFeedId) { + feed.name = feed.name // If the name has been changed on the server remove the locally edited name - webFeed.editedName = nil - webFeed.homePageURL = feed.homePageURL - webFeed.externalID = String(feed.feedID) - webFeed.faviconURL = feed.faviconURL + feed.editedName = nil + feed.homePageURL = feed.homePageURL + feed.externalID = String(feed.feedID) + feed.faviconURL = feed.faviconURL } else { feedsToAdd.insert(feed) @@ -118,9 +118,9 @@ extension NewsBlurAccountDelegate { // Actually add feeds all in one go, so we don’t trigger various rebuilding things that Account does. feedsToAdd.forEach { feed in - let webFeed = account.createWebFeed(with: feed.name, url: feed.feedURL, webFeedID: String(feed.feedID), homePageURL: feed.homePageURL) - webFeed.externalID = String(feed.feedID) - account.addWebFeed(webFeed) + let feed = account.createFeed(with: feed.name, url: feed.feedURL, feedID: String(feed.feedID), homePageURL: feed.homePageURL) + feed.externalID = String(feed.feedID) + account.addFeed(feed) } } @@ -155,25 +155,25 @@ extension NewsBlurAccountDelegate { guard let folder = folderDict[folderName] else { return } // Move any feeds not in the folder to the account - for feed in folder.topLevelWebFeeds { - if !newsBlurFolderFeedIDs.contains(feed.webFeedID) { - folder.removeWebFeed(feed) + for feed in folder.topLevelFeeds { + if !newsBlurFolderFeedIDs.contains(feed.feedID) { + folder.removeFeed(feed) clearFolderRelationship(for: feed, withFolderName: folder.name ?? "") - account.addWebFeed(feed) + account.addFeed(feed) } } // Add any feeds not in the folder - let folderFeedIds = folder.topLevelWebFeeds.map { $0.webFeedID } + let folderFeedIds = folder.topLevelFeeds.map { $0.feedID } for relationship in folderRelationships { let folderFeedID = String(relationship.feedID) if !folderFeedIds.contains(folderFeedID) { - guard let feed = account.existingWebFeed(withWebFeedID: folderFeedID) else { + guard let feed = account.existingFeed(withFeedID: folderFeedID) else { continue } saveFolderRelationship(for: feed, withFolderName: folderName, id: relationship.folderName) - folder.addWebFeed(feed) + folder.addFeed(feed) } } } @@ -182,27 +182,27 @@ extension NewsBlurAccountDelegate { // in folders and we need to remove them all from the account level. if let folderRelationships = newsBlurFolderDict[" "] { let newsBlurFolderFeedIDs = folderRelationships.map { String($0.feedID) } - for feed in account.topLevelWebFeeds { - if !newsBlurFolderFeedIDs.contains(feed.webFeedID) { - account.removeWebFeed(feed) + for feed in account.topLevelFeeds { + if !newsBlurFolderFeedIDs.contains(feed.feedID) { + account.removeFeed(feed) } } } else { - for feed in account.topLevelWebFeeds { - account.removeWebFeed(feed) + for feed in account.topLevelFeeds { + account.removeFeed(feed) } } } - func clearFolderRelationship(for feed: WebFeed, withFolderName folderName: String) { + func clearFolderRelationship(for feed: Feed, withFolderName folderName: String) { if var folderRelationship = feed.folderRelationship { folderRelationship[folderName] = nil feed.folderRelationship = folderRelationship } } - func saveFolderRelationship(for feed: WebFeed, withFolderName folderName: String, id: String) { + func saveFolderRelationship(for feed: Feed, withFolderName folderName: String, id: String) { if var folderRelationship = feed.folderRelationship { folderRelationship[folderName] = id feed.folderRelationship = folderRelationship @@ -412,31 +412,31 @@ extension NewsBlurAccountDelegate { } } - func createFeed(account: Account, feed: NewsBlurFeed?, name: String?, container: Container, completion: @escaping (Result) -> Void) { + func createFeed(account: Account, feed: NewsBlurFeed?, name: String?, container: Container, completion: @escaping (Result) -> Void) { guard let feed = feed else { completion(.failure(NewsBlurError.invalidParameter)) return } DispatchQueue.main.async { - let webFeed = account.createWebFeed(with: feed.name, url: feed.feedURL, webFeedID: String(feed.feedID), homePageURL: feed.homePageURL) - webFeed.externalID = String(feed.feedID) - webFeed.faviconURL = feed.faviconURL + let feed = account.createFeed(with: feed.name, url: feed.feedURL, feedID: String(feed.feedID), homePageURL: feed.homePageURL) + feed.externalID = String(feed.feedID) + feed.faviconURL = feed.faviconURL - account.addWebFeed(webFeed, to: container) { result in + account.addFeed(feed, to: container) { result in switch result { case .success: if let name = name { - account.renameWebFeed(webFeed, to: name) { result in + account.renameFeed(feed, to: name) { result in switch result { case .success: - self.initialFeedDownload(account: account, feed: webFeed, completion: completion) + self.initialFeedDownload(account: account, feed: feed, completion: completion) case .failure(let error): completion(.failure(error)) } } } else { - self.initialFeedDownload(account: account, feed: webFeed, completion: completion) + self.initialFeedDownload(account: account, feed: feed, completion: completion) } case .failure(let error): completion(.failure(error)) @@ -445,10 +445,10 @@ extension NewsBlurAccountDelegate { } } - func downloadFeed(account: Account, feed: WebFeed, page: Int, completion: @escaping (Result) -> Void) { + func downloadFeed(account: Account, feed: Feed, page: Int, completion: @escaping (Result) -> Void) { refreshProgress.addToNumberOfTasksAndRemaining(1) - caller.retrieveStories(feedID: feed.webFeedID, page: page) { result in + caller.retrieveStories(feedID: feed.feedID, page: page) { result in switch result { case .success((let stories, _)): // No more stories @@ -484,7 +484,7 @@ extension NewsBlurAccountDelegate { } } - func initialFeedDownload(account: Account, feed: WebFeed, completion: @escaping (Result) -> Void) { + func initialFeedDownload(account: Account, feed: Feed, completion: @escaping (Result) -> Void) { refreshProgress.addToNumberOfTasksAndRemaining(1) // Download the initial articles @@ -513,7 +513,7 @@ extension NewsBlurAccountDelegate { } } - func deleteFeed(for account: Account, with feed: WebFeed, from container: Container?, completion: @escaping (Result) -> Void) { + func deleteFeed(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result) -> Void) { // This error should never happen guard let feedID = feed.externalID else { completion(.failure(NewsBlurError.invalidParameter)) @@ -529,19 +529,19 @@ extension NewsBlurAccountDelegate { switch result { case .success: DispatchQueue.main.async { - let feedID = feed.webFeedID + let feedID = feed.feedID if folderName == nil { - account.removeWebFeed(feed) + account.removeFeed(feed) } if let folders = account.folders { for folder in folders where folderName != nil && folder.name == folderName { - folder.removeWebFeed(feed) + folder.removeFeed(feed) } } - if account.existingWebFeed(withWebFeedID: feedID) != nil { + if account.existingFeed(withFeedID: feedID) != nil { account.clearFeedMetadata(feed) } diff --git a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift index 51f519924..949586d4c 100644 --- a/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift +++ b/Modules/Account/Sources/Account/NewsBlur/NewsBlurAccountDelegate.swift @@ -333,17 +333,17 @@ final class NewsBlurAccountDelegate: AccountDelegate { return datePublished >= since } - let webFeedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL }).mapValues { + let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL }).mapValues { Set($0) } - account.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: true) { error in + account.update(feedIDsAndItems: feedIDsAndItems, defaultRead: true) { error in if let error = error { completion(.failure(error)) return } - completion(.success(!webFeedIDsAndItems.isEmpty)) + completion(.success(!feedIDsAndItems.isEmpty)) } } @@ -402,7 +402,7 @@ final class NewsBlurAccountDelegate: AccountDelegate { } var feedIDs: [String] = [] - for feed in folder.topLevelWebFeeds { + for feed in folder.topLevelFeeds { if (feed.folderRelationship?.count ?? 0) > 1 { clearFolderRelationship(for: feed, withFolderName: folderToRemove) } else if let feedID = feed.externalID { @@ -425,7 +425,7 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } - func createWebFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> ()) { + func createFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> ()) { refreshProgress.addToNumberOfTasksAndRemaining(1) let folderName = (container as? Folder)?.name @@ -444,7 +444,7 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } - func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result) -> ()) { + func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> ()) { guard let feedID = feed.externalID else { completion(.failure(NewsBlurError.invalidParameter)) return @@ -471,11 +471,11 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } - func addWebFeed(for account: Account, with feed: WebFeed, to container: Container, completion: @escaping (Result) -> ()) { + func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result) -> ()) { guard let folder = container as? Folder else { DispatchQueue.main.async { if let account = container as? Account { - account.addWebFeed(feed) + account.addFeed(feed) } completion(.success(())) } @@ -485,16 +485,16 @@ final class NewsBlurAccountDelegate: AccountDelegate { let folderName = folder.name ?? "" saveFolderRelationship(for: feed, withFolderName: folderName, id: folderName) - folder.addWebFeed(feed) + folder.addFeed(feed) completion(.success(())) } - func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result) -> ()) { + func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> ()) { deleteFeed(for: account, with: feed, from: container, completion: completion) } - func moveWebFeed(for account: Account, with feed: WebFeed, from: Container, to: Container, completion: @escaping (Result) -> ()) { + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> ()) { guard let feedID = feed.externalID else { completion(.failure(NewsBlurError.invalidParameter)) return @@ -511,8 +511,8 @@ final class NewsBlurAccountDelegate: AccountDelegate { switch result { case .success: - from.removeWebFeed(feed) - to.addWebFeed(feed) + from.removeFeed(feed) + to.addFeed(feed) completion(.success(())) case .failure(let error): @@ -521,9 +521,9 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } - func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result) -> ()) { - if let existingFeed = account.existingWebFeed(withURL: feed.url) { - account.addWebFeed(existingFeed, to: container) { result in + func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result) -> ()) { + if let existingFeed = account.existingFeed(withURL: feed.url) { + account.addFeed(existingFeed, to: container) { result in switch result { case .success: completion(.success(())) @@ -532,7 +532,7 @@ final class NewsBlurAccountDelegate: AccountDelegate { } } } else { - createWebFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in + createFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in switch result { case .success: completion(.success(())) @@ -549,10 +549,10 @@ final class NewsBlurAccountDelegate: AccountDelegate { return } - var feedsToRestore: [WebFeed] = [] - for feed in folder.topLevelWebFeeds { + var feedsToRestore: [Feed] = [] + for feed in folder.topLevelFeeds { feedsToRestore.append(feed) - folder.topLevelWebFeeds.remove(feed) + folder.topLevelFeeds.remove(feed) } let group = DispatchGroup() @@ -564,7 +564,7 @@ final class NewsBlurAccountDelegate: AccountDelegate { case .success(let folder): for feed in feedsToRestore { group.enter() - self.restoreWebFeed(for: account, feed: feed, container: folder) { result in + self.restoreFeed(for: account, feed: feed, container: folder) { result in group.leave() switch result { case .success: diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 00ebd4ad8..0a4703137 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -329,7 +329,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate { let group = DispatchGroup() - for feed in folder.topLevelWebFeeds { + for feed in folder.topLevelFeeds { if feed.folderRelationship?.count ?? 0 > 1 { @@ -389,7 +389,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } } - func createWebFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { + func createFeed(for account: Account, url: String, name: String?, container: Container, validateFeed: Bool, completion: @escaping (Result) -> Void) { guard let url = URL(string: url) else { completion(.failure(ReaderAPIAccountDelegateError.invalidParameter)) return @@ -438,7 +438,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } - func renameWebFeed(for account: Account, with feed: WebFeed, to name: String, completion: @escaping (Result) -> Void) { + func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result) -> Void) { // This error should never happen guard let subscriptionID = feed.externalID else { @@ -465,7 +465,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } - func removeWebFeed(for account: Account, with feed: WebFeed, from container: Container, completion: @escaping (Result) -> Void) { + func removeFeed(for account: Account, with feed: Feed, from container: Container, completion: @escaping (Result) -> Void) { guard let subscriptionID = feed.externalID else { completion(.failure(ReaderAPIAccountDelegateError.invalidParameter)) return @@ -478,10 +478,10 @@ final class ReaderAPIAccountDelegate: AccountDelegate { case .success: DispatchQueue.main.async { account.clearFeedMetadata(feed) - account.removeWebFeed(feed) + account.removeFeed(feed) if let folders = account.folders { for folder in folders { - folder.removeWebFeed(feed) + folder.removeFeed(feed) } } completion(.success(())) @@ -495,9 +495,9 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } } - func moveWebFeed(for account: Account, with feed: WebFeed, from: Container, to: Container, completion: @escaping (Result) -> Void) { + func moveFeed(for account: Account, with feed: Feed, from: Container, to: Container, completion: @escaping (Result) -> Void) { if from is Account { - addWebFeed(for: account, with: feed, to: to, completion: completion) + addFeed(for: account, with: feed, to: to, completion: completion) } else { guard let subscriptionId = feed.externalID, @@ -513,8 +513,8 @@ final class ReaderAPIAccountDelegate: AccountDelegate { self.refreshProgress.completeTask() switch result { case .success: - from.removeWebFeed(feed) - to.addWebFeed(feed) + from.removeFeed(feed) + to.addFeed(feed) completion(.success(())) case .failure(let error): completion(.failure(error)) @@ -523,7 +523,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } } - func addWebFeed(for account: Account, with feed: WebFeed, to container: Container, completion: @escaping (Result) -> Void) { + func addFeed(for account: Account, with feed: Feed, to container: Container, completion: @escaping (Result) -> Void) { if let folder = container as? Folder, let feedExternalID = feed.externalID { refreshProgress.addToNumberOfTasksAndRemaining(1) caller.createTagging(subscriptionID: feedExternalID, tagName: folder.name ?? "") { result in @@ -532,8 +532,8 @@ final class ReaderAPIAccountDelegate: AccountDelegate { case .success: DispatchQueue.main.async { self.saveFolderRelationship(for: feed, folderExternalID: folder.externalID, feedExternalID: feedExternalID) - account.removeWebFeed(feed) - folder.addWebFeed(feed) + account.removeFeed(feed) + folder.addFeed(feed) completion(.success(())) } case .failure(let error): @@ -553,10 +553,10 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } } - func restoreWebFeed(for account: Account, feed: WebFeed, container: Container, completion: @escaping (Result) -> Void) { + func restoreFeed(for account: Account, feed: Feed, container: Container, completion: @escaping (Result) -> Void) { - if let existingFeed = account.existingWebFeed(withURL: feed.url) { - account.addWebFeed(existingFeed, to: container) { result in + if let existingFeed = account.existingFeed(withURL: feed.url) { + account.addFeed(existingFeed, to: container) { result in switch result { case .success: completion(.success(())) @@ -565,7 +565,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate { } } } else { - createWebFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in + createFeed(for: account, url: feed.url, name: feed.editedName, container: container, validateFeed: true) { result in switch result { case .success: completion(.success(())) @@ -581,12 +581,12 @@ final class ReaderAPIAccountDelegate: AccountDelegate { let group = DispatchGroup() - for feed in folder.topLevelWebFeeds { + for feed in folder.topLevelFeeds { - folder.topLevelWebFeeds.remove(feed) + folder.topLevelFeeds.remove(feed) group.enter() - restoreWebFeed(for: account, feed: feed, container: folder) { result in + restoreFeed(for: account, feed: feed, container: folder) { result in group.leave() switch result { case .success: @@ -716,8 +716,8 @@ private extension ReaderAPIAccountDelegate { if let folders = account.folders { folders.forEach { folder in if !readerFolderExternalIDs.contains(folder.externalID ?? "") { - for feed in folder.topLevelWebFeeds { - account.addWebFeed(feed) + for feed in folder.topLevelFeeds { + account.addFeed(feed) clearFolderRelationship(for: feed, folderExternalID: folder.externalID) } account.removeFolder(folder) @@ -755,32 +755,32 @@ private extension ReaderAPIAccountDelegate { // Remove any feeds that are no longer in the subscriptions if let folders = account.folders { for folder in folders { - for feed in folder.topLevelWebFeeds { - if !subFeedIds.contains(feed.webFeedID) { - folder.removeWebFeed(feed) + for feed in folder.topLevelFeeds { + if !subFeedIds.contains(feed.feedID) { + folder.removeFeed(feed) } } } } - for feed in account.topLevelWebFeeds { - if !subFeedIds.contains(feed.webFeedID) { + for feed in account.topLevelFeeds { + if !subFeedIds.contains(feed.feedID) { account.clearFeedMetadata(feed) - account.removeWebFeed(feed) + account.removeFeed(feed) } } // Add any feeds we don't have and update any we do subscriptions.forEach { subscription in - if let feed = account.existingWebFeed(withWebFeedID: subscription.feedID) { + if let feed = account.existingFeed(withFeedID: subscription.feedID) { feed.name = subscription.name feed.editedName = nil feed.homePageURL = subscription.homePageURL } else { - let feed = account.createWebFeed(with: subscription.name, url: subscription.url, webFeedID: subscription.feedID, homePageURL: subscription.homePageURL) + let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: subscription.feedID, homePageURL: subscription.homePageURL) feed.externalID = subscription.feedID - account.addWebFeed(feed) + account.addFeed(feed) } } @@ -815,25 +815,25 @@ private extension ReaderAPIAccountDelegate { let taggingFeedIDs = groupedTaggings.map { $0.feedID } // Move any feeds not in the folder to the account - for feed in folder.topLevelWebFeeds { - if !taggingFeedIDs.contains(feed.webFeedID) { - folder.removeWebFeed(feed) + for feed in folder.topLevelFeeds { + if !taggingFeedIDs.contains(feed.feedID) { + folder.removeFeed(feed) clearFolderRelationship(for: feed, folderExternalID: folder.externalID) - account.addWebFeed(feed) + account.addFeed(feed) } } // Add any feeds not in the folder - let folderFeedIds = folder.topLevelWebFeeds.map { $0.webFeedID } + let folderFeedIds = folder.topLevelFeeds.map { $0.feedID } for subscription in groupedTaggings { let taggingFeedID = subscription.feedID if !folderFeedIds.contains(taggingFeedID) { - guard let feed = account.existingWebFeed(withWebFeedID: taggingFeedID) else { + guard let feed = account.existingFeed(withFeedID: taggingFeedID) else { continue } saveFolderRelationship(for: feed, folderExternalID: folderExternalID, feedExternalID: subscription.feedID) - folder.addWebFeed(feed) + folder.addFeed(feed) } } @@ -842,9 +842,9 @@ private extension ReaderAPIAccountDelegate { let taggedFeedIDs = Set(subscriptions.filter({ !$0.categories.isEmpty }).map { String($0.feedID) }) // Remove all feeds from the account container that have a tag - for feed in account.topLevelWebFeeds { - if taggedFeedIDs.contains(feed.webFeedID) { - account.removeWebFeed(feed) + for feed in account.topLevelFeeds { + if taggedFeedIDs.contains(feed.feedID) { + account.removeFeed(feed) } } } @@ -898,13 +898,13 @@ private extension ReaderAPIAccountDelegate { } - func clearFolderRelationship(for feed: WebFeed, folderExternalID: String?) { + func clearFolderRelationship(for feed: Feed, folderExternalID: String?) { guard var folderRelationship = feed.folderRelationship, let folderExternalID = folderExternalID else { return } folderRelationship[folderExternalID] = nil feed.folderRelationship = folderRelationship } - func saveFolderRelationship(for feed: WebFeed, folderExternalID: String?, feedExternalID: String) { + func saveFolderRelationship(for feed: Feed, folderExternalID: String?, feedExternalID: String) { guard let folderExternalID = folderExternalID else { return } if var folderRelationship = feed.folderRelationship { folderRelationship[folderExternalID] = feedExternalID @@ -914,18 +914,18 @@ private extension ReaderAPIAccountDelegate { } } - func createFeed( account: Account, subscription sub: ReaderAPISubscription, name: String?, container: Container, completion: @escaping (Result) -> Void) { + func createFeed( account: Account, subscription sub: ReaderAPISubscription, name: String?, container: Container, completion: @escaping (Result) -> Void) { DispatchQueue.main.async { - let feed = account.createWebFeed(with: sub.name, url: sub.url, webFeedID: String(sub.feedID), homePageURL: sub.homePageURL) + let feed = account.createFeed(with: sub.name, url: sub.url, feedID: String(sub.feedID), homePageURL: sub.homePageURL) feed.externalID = String(sub.feedID) - account.addWebFeed(feed, to: container) { result in + account.addFeed(feed, to: container) { result in switch result { case .success: if let name = name { - self.renameWebFeed(for: account, with: feed, to: name) { result in + self.renameFeed(for: account, with: feed, to: name) { result in switch result { case .success: self.initialFeedDownload(account: account, feed: feed, completion: completion) @@ -945,11 +945,11 @@ private extension ReaderAPIAccountDelegate { } - func initialFeedDownload( account: Account, feed: WebFeed, completion: @escaping (Result) -> Void) { + func initialFeedDownload( account: Account, feed: Feed, completion: @escaping (Result) -> Void) { refreshProgress.addToNumberOfTasksAndRemaining(5) // Download the initial articles - self.caller.retrieveItemIDs(type: .allForFeed, webFeedID: feed.webFeedID) { result in + self.caller.retrieveItemIDs(type: .allForFeed, feedID: feed.feedID) { result in self.refreshProgress.completeTask() switch result { case .success(let articleIDs): @@ -1029,8 +1029,8 @@ private extension ReaderAPIAccountDelegate { func processEntries(account: Account, entries: [ReaderAPIEntry]?, completion: @escaping VoidCompletionBlock) { let parsedItems = mapEntriesToParsedItems(account: account, entries: entries) - let webFeedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) } - account.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: true) { _ in + let feedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) } + account.update(feedIDsAndItems: feedIDsAndItems, defaultRead: true) { _ in completion() } } diff --git a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift index a769d956c..fd2995c25 100644 --- a/Modules/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift +++ b/Modules/Account/Sources/Account/ReaderAPI/ReaderAPICaller.swift @@ -554,7 +554,7 @@ final class ReaderAPICaller: NSObject { } - func retrieveItemIDs(type: ItemIDType, webFeedID: String? = nil, completion: @escaping ((Result<[String], Error>) -> Void)) { + func retrieveItemIDs(type: ItemIDType, feedID: String? = nil, completion: @escaping ((Result<[String], Error>) -> Void)) { guard let baseURL = apiBaseURL else { completion(.failure(CredentialsError.incompleteCredentials)) return @@ -579,13 +579,13 @@ final class ReaderAPICaller: NSObject { queryItems.append(URLQueryItem(name: "ot", value: String(Int(sinceTimeInterval)))) queryItems.append(URLQueryItem(name: "s", value: ReaderStreams.readingList.rawValue)) case .allForFeed: - guard let webFeedID = webFeedID else { + guard let feedID = feedID else { completion(.failure(ReaderAPIAccountDelegateError.invalidParameter)) return } let sinceTimeInterval = (Calendar.current.date(byAdding: .month, value: -3, to: Date()) ?? Date()).timeIntervalSince1970 queryItems.append(URLQueryItem(name: "ot", value: String(Int(sinceTimeInterval)))) - queryItems.append(URLQueryItem(name: "s", value: webFeedID)) + queryItems.append(URLQueryItem(name: "s", value: feedID)) case .unread: queryItems.append(URLQueryItem(name: "s", value: ReaderStreams.readingList.rawValue)) queryItems.append(URLQueryItem(name: "xt", value: ReaderState.read.rawValue)) diff --git a/Modules/Account/Sources/Account/SidebarItemIdentifier.swift b/Modules/Account/Sources/Account/SidebarItemIdentifier.swift index 2af20201e..579d322c8 100644 --- a/Modules/Account/Sources/Account/SidebarItemIdentifier.swift +++ b/Modules/Account/Sources/Account/SidebarItemIdentifier.swift @@ -16,7 +16,7 @@ public enum SidebarItemIdentifier: CustomStringConvertible, Hashable, Equatable case smartFeed(String) // String is a unique identifier case script(String) // String is a unique identifier - case webFeed(String, String) // accountID, webFeedID + case feed(String, String) // accountID, feedID case folder(String, String) // accountID, folderName public var description: String { @@ -25,8 +25,8 @@ public enum SidebarItemIdentifier: CustomStringConvertible, Hashable, Equatable return "smartFeed: \(id)" case .script(let id): return "script: \(id)" - case .webFeed(let accountID, let webFeedID): - return "feed: \(accountID)_\(webFeedID)" + case .feed(let accountID, let feedID): + return "feed: \(accountID)_\(feedID)" case .folder(let accountID, let folderName): return "folder: \(accountID)_\(folderName)" } @@ -44,11 +44,11 @@ public enum SidebarItemIdentifier: CustomStringConvertible, Hashable, Equatable "type": "script", "id": id ] - case .webFeed(let accountID, let webFeedID): + case .feed(let accountID, let feedID): return [ "type": "feed", "accountID": accountID, - "webFeedID": webFeedID + "feedID": feedID ] case .folder(let accountID, let folderName): return [ @@ -70,8 +70,8 @@ public enum SidebarItemIdentifier: CustomStringConvertible, Hashable, Equatable guard let id = userInfo["id"] as? String else { return nil } self = SidebarItemIdentifier.script(id) case "feed": - guard let accountID = userInfo["accountID"] as? String, let webFeedID = userInfo["webFeedID"] as? String else { return nil } - self = SidebarItemIdentifier.webFeed(accountID, webFeedID) + guard let accountID = userInfo["accountID"] as? String, let feedID = userInfo["feedID"] as? String else { return nil } + self = SidebarItemIdentifier.feed(accountID, feedID) case "folder": guard let accountID = userInfo["accountID"] as? String, let folderName = userInfo["folderName"] as? String else { return nil } self = SidebarItemIdentifier.folder(accountID, folderName) diff --git a/Modules/Account/Tests/AccountTests/Feedbin/AccountFeedbinFolderContentsSyncTest.swift b/Modules/Account/Tests/AccountTests/Feedbin/AccountFeedbinFolderContentsSyncTest.swift index 78c7867e9..5aa095ad9 100644 --- a/Modules/Account/Tests/AccountTests/Feedbin/AccountFeedbinFolderContentsSyncTest.swift +++ b/Modules/Account/Tests/AccountTests/Feedbin/AccountFeedbinFolderContentsSyncTest.swift @@ -33,8 +33,8 @@ final class AccountFeedbinFolderContentsSyncTest: XCTestCase { waitForExpectations(timeout: 5, handler: nil) let folder = account.folders?.filter { $0.name == "Developers" } .first! - XCTAssertEqual(156, folder?.topLevelWebFeeds.count ?? 0) - XCTAssertEqual(2, account.topLevelWebFeeds.count) + XCTAssertEqual(156, folder?.topLevelFeeds.count ?? 0) + XCTAssertEqual(2, account.topLevelFeeds.count) // Test Adding a Feed to the folder testTransport.testFiles["https://api.feedbin.com/v2/taggings.json"] = "JSON/taggings_add.json" @@ -45,8 +45,8 @@ final class AccountFeedbinFolderContentsSyncTest: XCTestCase { } waitForExpectations(timeout: 5, handler: nil) - XCTAssertEqual(157, folder?.topLevelWebFeeds.count ?? 0) - XCTAssertEqual(1, account.topLevelWebFeeds.count) + XCTAssertEqual(157, folder?.topLevelFeeds.count ?? 0) + XCTAssertEqual(1, account.topLevelFeeds.count) // Test Deleting some Feeds from the folder testTransport.testFiles["https://api.feedbin.com/v2/taggings.json"] = "JSON/taggings_delete.json" @@ -57,8 +57,8 @@ final class AccountFeedbinFolderContentsSyncTest: XCTestCase { } waitForExpectations(timeout: 5, handler: nil) - XCTAssertEqual(153, folder?.topLevelWebFeeds.count ?? 0) - XCTAssertEqual(5, account.topLevelWebFeeds.count) + XCTAssertEqual(153, folder?.topLevelFeeds.count ?? 0) + XCTAssertEqual(5, account.topLevelFeeds.count) TestAccountManager.shared.deleteAccount(account) diff --git a/Modules/Account/Tests/AccountTests/Feedbin/AccountFeedbinSyncTest.swift b/Modules/Account/Tests/AccountTests/Feedbin/AccountFeedbinSyncTest.swift index cf48425ca..233ce133e 100644 --- a/Modules/Account/Tests/AccountTests/Feedbin/AccountFeedbinSyncTest.swift +++ b/Modules/Account/Tests/AccountTests/Feedbin/AccountFeedbinSyncTest.swift @@ -36,9 +36,9 @@ final class AccountFeedbinSyncTest: XCTestCase { } waitForExpectations(timeout: 5, handler: nil) - XCTAssertEqual(224, account.flattenedWebFeeds().count) + XCTAssertEqual(224, account.flattenedFeeds().count) - let daringFireball = account.idToWebFeedDictionary["1296379"] + let daringFireball = account.idToFeedDictionary["1296379"] XCTAssertEqual("Daring Fireball", daringFireball!.name) XCTAssertEqual("https://daringfireball.net/feeds/json", daringFireball!.url) XCTAssertEqual("https://daringfireball.net/", daringFireball!.homePageURL) @@ -57,9 +57,9 @@ final class AccountFeedbinSyncTest: XCTestCase { } waitForExpectations(timeout: 5, handler: nil) - XCTAssertEqual(225, account.flattenedWebFeeds().count) + XCTAssertEqual(225, account.flattenedFeeds().count) - let bPixels = account.idToWebFeedDictionary["1096623"] + let bPixels = account.idToFeedDictionary["1096623"] XCTAssertEqual("Beautiful Pixels", bPixels?.name) XCTAssertEqual("https://feedpress.me/beautifulpixels", bPixels?.url) XCTAssertEqual("https://beautifulpixels.com/", bPixels?.homePageURL) diff --git a/Modules/Account/Tests/AccountTests/Feedly/FeedlyCreateFeedsForCollectionFoldersOperationTests.swift b/Modules/Account/Tests/AccountTests/Feedly/FeedlyCreateFeedsForCollectionFoldersOperationTests.swift index 5fdcd1ca5..8c82270bf 100644 --- a/Modules/Account/Tests/AccountTests/Feedly/FeedlyCreateFeedsForCollectionFoldersOperationTests.swift +++ b/Modules/Account/Tests/AccountTests/Feedly/FeedlyCreateFeedsForCollectionFoldersOperationTests.swift @@ -59,7 +59,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase { completionExpectation.fulfill() } - XCTAssertTrue(account.flattenedWebFeeds().isEmpty, "Expected empty account.") + XCTAssertTrue(account.flattenedFeeds().isEmpty, "Expected empty account.") MainThreadOperationQueue.shared.add(createFeeds) @@ -73,8 +73,8 @@ final class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase { .flatMap { $0 } .map { $0.title }) - let accountFeeds = account.flattenedWebFeeds() - let ingestedIds = Set(accountFeeds.map { $0.webFeedID }) + let accountFeeds = account.flattenedFeeds() + let ingestedIds = Set(accountFeeds.map { $0.feedID }) let ingestedTitles = Set(accountFeeds.map { $0.nameForDisplay }) let missingIds = feedIds.subtracting(ingestedIds) @@ -92,7 +92,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase { let ingestedFolderAndFeedIds = (account.folders ?? Set()) .sorted { $0.externalID! < $1.externalID! } .compactMap { folder -> [String: [String]]? in - return [folder.externalID!: folder.topLevelWebFeeds.map { $0.webFeedID }.sorted(by: <)] + return [folder.externalID!: folder.topLevelFeeds.map { $0.feedID }.sorted(by: <)] } XCTAssertEqual(expectedFolderAndFeedIds, ingestedFolderAndFeedIds, "Did not ingest feeds in their corresponding folders.") @@ -130,7 +130,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase { completionExpectation.fulfill() } - XCTAssertTrue(account.flattenedWebFeeds().isEmpty, "Expected empty account.") + XCTAssertTrue(account.flattenedFeeds().isEmpty, "Expected empty account.") MainThreadOperationQueue.shared.add(createFeeds) @@ -166,8 +166,8 @@ final class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase { .flatMap { $0 } .map { $0.title }) - let accountFeeds = account.flattenedWebFeeds() - let ingestedIds = Set(accountFeeds.map { $0.webFeedID }) + let accountFeeds = account.flattenedFeeds() + let ingestedIds = Set(accountFeeds.map { $0.feedID }) let ingestedTitles = Set(accountFeeds.map { $0.nameForDisplay }) XCTAssertEqual(ingestedIds.count, feedIds.count) @@ -188,7 +188,7 @@ final class FeedlyCreateFeedsForCollectionFoldersOperationTests: XCTestCase { let ingestedFolderAndFeedIds = (account.folders ?? Set()) .sorted { $0.externalID! < $1.externalID! } .compactMap { folder -> [String: [String]]? in - return [folder.externalID!: folder.topLevelWebFeeds.map { $0.webFeedID }.sorted(by: <)] + return [folder.externalID!: folder.topLevelFeeds.map { $0.feedID }.sorted(by: <)] } XCTAssertEqual(expectedFolderAndFeedIds, ingestedFolderAndFeedIds, "Did not ingest feeds to their corresponding folders.") diff --git a/Modules/Account/Tests/AccountTests/Feedly/FeedlyEntryParserTests.swift b/Modules/Account/Tests/AccountTests/Feedly/FeedlyEntryParserTests.swift index 4b28db92d..f32f7380b 100644 --- a/Modules/Account/Tests/AccountTests/Feedly/FeedlyEntryParserTests.swift +++ b/Modules/Account/Tests/AccountTests/Feedly/FeedlyEntryParserTests.swift @@ -55,7 +55,7 @@ final class FeedlyEntryParserTests: XCTestCase { XCTAssertEqual(item.uniqueID, entry.id) // The following is not an error. - // The feedURL must match the webFeedID for the article to be connected to its matching feed. + // The feedURL must match the feedID for the article to be connected to its matching feed. XCTAssertEqual(item.feedURL, origin.streamId) XCTAssertEqual(item.title, entry.title) XCTAssertEqual(item.contentHTML, content.content) diff --git a/Modules/Account/Tests/AccountTests/Feedly/FeedlyFeedParserTests.swift b/Modules/Account/Tests/AccountTests/Feedly/FeedlyFeedParserTests.swift index af50e46cf..4ca0ede17 100644 --- a/Modules/Account/Tests/AccountTests/Feedly/FeedlyFeedParserTests.swift +++ b/Modules/Account/Tests/AccountTests/Feedly/FeedlyFeedParserTests.swift @@ -22,7 +22,7 @@ final class FeedlyFeedParserTests: XCTestCase { XCTAssertEqual(parser.title, name) XCTAssertEqual(parser.homePageURL, website) XCTAssertEqual(parser.url, url) - XCTAssertEqual(parser.webFeedID, id) + XCTAssertEqual(parser.feedID, id) } func testSanitization() { @@ -36,6 +36,6 @@ final class FeedlyFeedParserTests: XCTestCase { XCTAssertEqual(parser.title, name) XCTAssertEqual(parser.homePageURL, website) XCTAssertEqual(parser.url, url) - XCTAssertEqual(parser.webFeedID, id) + XCTAssertEqual(parser.feedID, id) } } diff --git a/Modules/Account/Tests/AccountTests/Feedly/FeedlyMirrorCollectionsAsFoldersOperationTests.swift b/Modules/Account/Tests/AccountTests/Feedly/FeedlyMirrorCollectionsAsFoldersOperationTests.swift index 02b77b056..ec75c6f68 100644 --- a/Modules/Account/Tests/AccountTests/Feedly/FeedlyMirrorCollectionsAsFoldersOperationTests.swift +++ b/Modules/Account/Tests/AccountTests/Feedly/FeedlyMirrorCollectionsAsFoldersOperationTests.swift @@ -180,7 +180,7 @@ final class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase { waitForExpectations(timeout: 2) - XCTAssertFalse(account.flattenedWebFeeds().isEmpty, "Expected account to have feeds.") + XCTAssertFalse(account.flattenedFeeds().isEmpty, "Expected account to have feeds.") } // Now that the folders are added, remove them all. @@ -197,7 +197,7 @@ final class FeedlyMirrorCollectionsAsFoldersOperationTests: XCTestCase { waitForExpectations(timeout: 2) - let feeds = account.flattenedWebFeeds() + let feeds = account.flattenedFeeds() XCTAssertTrue(feeds.isEmpty) } diff --git a/Modules/Account/Tests/AccountTests/Feedly/FeedlyTestSupport.swift b/Modules/Account/Tests/AccountTests/Feedly/FeedlyTestSupport.swift index 7df79f41b..29dc69a0d 100644 --- a/Modules/Account/Tests/AccountTests/Feedly/FeedlyTestSupport.swift +++ b/Modules/Account/Tests/AccountTests/Feedly/FeedlyTestSupport.swift @@ -134,12 +134,12 @@ final class FeedlyTestSupport { return } let collectionFeeds = collection["feeds"] as! [[String: Any]] - let folderFeeds = folder.topLevelWebFeeds + let folderFeeds = folder.topLevelFeeds XCTAssertEqual(collectionFeeds.count, folderFeeds.count) let collectionFeedIds = Set(collectionFeeds.map { $0["id"] as! String }) - let folderFeedIds = Set(folderFeeds.map { $0.webFeedID }) + let folderFeedIds = Set(folderFeeds.map { $0.feedID }) let missingFeedIds = collectionFeedIds.subtracting(folderFeedIds) XCTAssertTrue(missingFeedIds.isEmpty, "Feeds with these ids were not found in the \"\(label)\" folder.") @@ -210,7 +210,7 @@ final class FeedlyTestSupport { for item in articleItems where item.id == article.articleID { XCTAssertEqual(article.uniqueID, item.id) XCTAssertEqual(article.contentHTML, item.content) - XCTAssertEqual(article.webFeedID, item.feedId) + XCTAssertEqual(article.feedID, item.feedId) XCTAssertEqual(article.rawExternalLink, item.externalUrl) } } diff --git a/Modules/Articles/Sources/Articles/Article.swift b/Modules/Articles/Sources/Articles/Article.swift index 89787fda8..30ec95d2f 100644 --- a/Modules/Articles/Sources/Articles/Article.swift +++ b/Modules/Articles/Sources/Articles/Article.swift @@ -14,7 +14,7 @@ public final class Article: Hashable { public let articleID: String // Unique database ID (possibly sync service ID) public let accountID: String - public let webFeedID: String // Likely a URL, but not necessarily + public let feedID: String // Likely a URL, but not necessarily public let uniqueID: String // Unique per feed (RSS guid, for example) public let title: String? public let contentHTML: String? @@ -29,9 +29,9 @@ public final class Article: Hashable { public let authors: Set? public let status: ArticleStatus - public init(accountID: String, articleID: String?, webFeedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, markdown: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, datePublished: Date?, dateModified: Date?, authors: Set?, status: ArticleStatus) { + public init(accountID: String, articleID: String?, feedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, markdown: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, datePublished: Date?, dateModified: Date?, authors: Set?, status: ArticleStatus) { self.accountID = accountID - self.webFeedID = webFeedID + self.feedID = feedID self.uniqueID = uniqueID self.title = title self.contentHTML = contentHTML @@ -50,12 +50,12 @@ public final class Article: Hashable { self.articleID = articleID } else { - self.articleID = Article.calculatedArticleID(webFeedID: webFeedID, uniqueID: uniqueID) + self.articleID = Article.calculatedArticleID(feedID: feedID, uniqueID: uniqueID) } } - public static func calculatedArticleID(webFeedID: String, uniqueID: String) -> String { - return databaseIDWithString("\(webFeedID) \(uniqueID)") + public static func calculatedArticleID(feedID: String, uniqueID: String) -> String { + return databaseIDWithString("\(feedID) \(uniqueID)") } // MARK: - Hashable @@ -67,7 +67,7 @@ public final class Article: Hashable { // MARK: - Equatable static public func ==(lhs: Article, rhs: Article) -> Bool { - return lhs.articleID == rhs.articleID && lhs.accountID == rhs.accountID && lhs.webFeedID == rhs.webFeedID && lhs.uniqueID == rhs.uniqueID && lhs.title == rhs.title && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.rawLink == rhs.rawLink && lhs.rawExternalLink == rhs.rawExternalLink && lhs.summary == rhs.summary && lhs.rawImageLink == rhs.rawImageLink && lhs.datePublished == rhs.datePublished && lhs.dateModified == rhs.dateModified && lhs.authors == rhs.authors + return lhs.articleID == rhs.articleID && lhs.accountID == rhs.accountID && lhs.feedID == rhs.feedID && lhs.uniqueID == rhs.uniqueID && lhs.title == rhs.title && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.rawLink == rhs.rawLink && lhs.rawExternalLink == rhs.rawExternalLink && lhs.summary == rhs.summary && lhs.rawImageLink == rhs.rawImageLink && lhs.datePublished == rhs.datePublished && lhs.dateModified == rhs.dateModified && lhs.authors == rhs.authors } } diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift index d3ab76355..27933e082 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift @@ -18,7 +18,7 @@ import Articles // Main thread only. -public typealias UnreadCountDictionary = [String: Int] // webFeedID: unreadCount +public typealias UnreadCountDictionary = [String: Int] // feedID: unreadCount public typealias UnreadCountDictionaryCompletionResult = Result public typealias UnreadCountDictionaryCompletionBlock = (UnreadCountDictionaryCompletionResult) -> Void @@ -101,14 +101,14 @@ public final class ArticlesDatabase { // MARK: - Fetching Articles - public func fetchArticles(_ webFeedID: String) throws -> Set
{ + public func fetchArticles(_ feedID: String) throws -> Set
{ Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - return try articlesTable.fetchArticles(webFeedID) + return try articlesTable.fetchArticles(feedID) } - public func fetchArticles(_ webFeedIDs: Set) throws -> Set
{ + public func fetchArticles(_ feedIDs: Set) throws -> Set
{ Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - return try articlesTable.fetchArticles(webFeedIDs) + return try articlesTable.fetchArticles(feedIDs) } public func fetchArticles(articleIDs: Set) throws -> Set
{ @@ -116,29 +116,29 @@ public final class ArticlesDatabase { return try articlesTable.fetchArticles(articleIDs: articleIDs) } - public func fetchUnreadArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ + public func fetchUnreadArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - return try articlesTable.fetchUnreadArticles(webFeedIDs, limit) + return try articlesTable.fetchUnreadArticles(feedIDs, limit) } - public func fetchTodayArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ + public func fetchTodayArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - return try articlesTable.fetchArticlesSince(webFeedIDs, todayCutoffDate(), limit) + return try articlesTable.fetchArticlesSince(feedIDs, todayCutoffDate(), limit) } - public func fetchStarredArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ + public func fetchStarredArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - return try articlesTable.fetchStarredArticles(webFeedIDs, limit) + return try articlesTable.fetchStarredArticles(feedIDs, limit) } - public func fetchStarredArticlesCount(_ webFeedIDs: Set) throws -> Int { + public func fetchStarredArticlesCount(_ feedIDs: Set) throws -> Int { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - return try articlesTable.fetchStarredArticlesCount(webFeedIDs) + return try articlesTable.fetchStarredArticlesCount(feedIDs) } - public func fetchArticlesMatching(_ searchString: String, _ webFeedIDs: Set) throws -> Set
{ + public func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set) throws -> Set
{ Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - return try articlesTable.fetchArticlesMatching(searchString, webFeedIDs) + return try articlesTable.fetchArticlesMatching(searchString, feedIDs) } public func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set) throws -> Set
{ @@ -148,14 +148,14 @@ public final class ArticlesDatabase { // MARK: - Fetching Articles Async - public func fetchArticlesAsync(_ webFeedID: String, _ completion: @escaping ArticleSetResultBlock) { + public func fetchArticlesAsync(_ feedID: String, _ completion: @escaping ArticleSetResultBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - articlesTable.fetchArticlesAsync(webFeedID, completion) + articlesTable.fetchArticlesAsync(feedID, completion) } - public func fetchArticlesAsync(_ webFeedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { + public func fetchArticlesAsync(_ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - articlesTable.fetchArticlesAsync(webFeedIDs, completion) + articlesTable.fetchArticlesAsync(feedIDs, completion) } public func fetchArticlesAsync(articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { @@ -163,24 +163,24 @@ public final class ArticlesDatabase { articlesTable.fetchArticlesAsync(articleIDs: articleIDs, completion) } - public func fetchUnreadArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + public func fetchUnreadArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - articlesTable.fetchUnreadArticlesAsync(webFeedIDs, limit, completion) + articlesTable.fetchUnreadArticlesAsync(feedIDs, limit, completion) } - public func fetchTodayArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + public func fetchTodayArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - articlesTable.fetchArticlesSinceAsync(webFeedIDs, todayCutoffDate(), limit, completion) + articlesTable.fetchArticlesSinceAsync(feedIDs, todayCutoffDate(), limit, completion) } - public func fetchedStarredArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + public func fetchedStarredArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - articlesTable.fetchStarredArticlesAsync(webFeedIDs, limit, completion) + articlesTable.fetchStarredArticlesAsync(feedIDs, limit, completion) } - public func fetchArticlesMatchingAsync(_ searchString: String, _ webFeedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { + public func fetchArticlesMatchingAsync(_ searchString: String, _ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - articlesTable.fetchArticlesMatchingAsync(searchString, webFeedIDs, completion) + articlesTable.fetchArticlesMatchingAsync(searchString, feedIDs, completion) } public func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { @@ -203,9 +203,9 @@ public final class ArticlesDatabase { } /// Fetch unread count for a single feed. - public func fetchUnreadCount(_ webFeedID: String, _ completion: @escaping SingleUnreadCountCompletionBlock) { + public func fetchUnreadCount(_ feedID: String, _ completion: @escaping SingleUnreadCountCompletionBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - let operation = FetchFeedUnreadCountOperation(webFeedID: webFeedID, databaseQueue: queue, cutoffDate: articlesTable.articleCutoffDate) + let operation = FetchFeedUnreadCountOperation(feedID: feedID, databaseQueue: queue, cutoffDate: articlesTable.articleCutoffDate) operation.completionBlock = { operation in let fetchOperation = operation as! FetchFeedUnreadCountOperation completion(fetchOperation.result) @@ -213,10 +213,10 @@ public final class ArticlesDatabase { operationQueue.add(operation) } - /// Fetch non-zero unread counts for given webFeedIDs. - public func fetchUnreadCounts(for webFeedIDs: Set, _ completion: @escaping UnreadCountDictionaryCompletionBlock) { + /// Fetch non-zero unread counts for given feedIDs. + public func fetchUnreadCounts(for feedIDs: Set, _ completion: @escaping UnreadCountDictionaryCompletionBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - let operation = FetchUnreadCountsForFeedsOperation(webFeedIDs: webFeedIDs, databaseQueue: queue) + let operation = FetchUnreadCountsForFeedsOperation(feedIDs: feedIDs, databaseQueue: queue) operation.completionBlock = { operation in let fetchOperation = operation as! FetchUnreadCountsForFeedsOperation completion(fetchOperation.result) @@ -224,35 +224,35 @@ public final class ArticlesDatabase { operationQueue.add(operation) } - public func fetchUnreadCountForToday(for webFeedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { + public func fetchUnreadCountForToday(for feedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - fetchUnreadCount(for: webFeedIDs, since: todayCutoffDate(), completion: completion) + fetchUnreadCount(for: feedIDs, since: todayCutoffDate(), completion: completion) } - public func fetchUnreadCount(for webFeedIDs: Set, since: Date, completion: @escaping SingleUnreadCountCompletionBlock) { + public func fetchUnreadCount(for feedIDs: Set, since: Date, completion: @escaping SingleUnreadCountCompletionBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - articlesTable.fetchUnreadCount(webFeedIDs, since, completion) + articlesTable.fetchUnreadCount(feedIDs, since, completion) } - public func fetchStarredAndUnreadCount(for webFeedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { + public func fetchStarredAndUnreadCount(for feedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - articlesTable.fetchStarredAndUnreadCount(webFeedIDs, completion) + articlesTable.fetchStarredAndUnreadCount(feedIDs, completion) } // MARK: - Saving, Updating, and Deleting Articles /// Update articles and save new ones — for feed-based systems (local and iCloud). - public func update(with parsedItems: Set, webFeedID: String, deleteOlder: Bool, completion: @escaping UpdateArticlesCompletionBlock) { + public func update(with parsedItems: Set, feedID: String, deleteOlder: Bool, completion: @escaping UpdateArticlesCompletionBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") precondition(retentionStyle == .feedBased) - articlesTable.update(parsedItems, webFeedID, deleteOlder, completion) + articlesTable.update(parsedItems, feedID, deleteOlder, completion) } /// Update articles and save new ones — for sync systems (Feedbin, Feedly, etc.). - public func update(webFeedIDsAndItems: [String: Set], defaultRead: Bool, completion: @escaping UpdateArticlesCompletionBlock) { + public func update(feedIDsAndItems: [String: Set], defaultRead: Bool, completion: @escaping UpdateArticlesCompletionBlock) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") precondition(retentionStyle == .syncSystem) - articlesTable.update(webFeedIDsAndItems, defaultRead, completion) + articlesTable.update(feedIDsAndItems, defaultRead, completion) } /// Delete articles @@ -340,12 +340,12 @@ public final class ArticlesDatabase { /// This prevents the database from growing forever. If we didn’t do this: /// 1) The database would grow to an inordinate size, and /// 2) the app would become very slow. - public func cleanupDatabaseAtStartup(subscribedToWebFeedIDs: Set) { + public func cleanupDatabaseAtStartup(subscribedToFeedIDs: Set) { Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") if retentionStyle == .syncSystem { articlesTable.deleteOldArticles() } - articlesTable.deleteArticlesNotInSubscribedToFeedIDs(subscribedToWebFeedIDs) + articlesTable.deleteArticlesNotInSubscribedToFeedIDs(subscribedToFeedIDs) articlesTable.deleteOldStatuses() } } diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift index bace3643c..bdfc7f353 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift @@ -48,20 +48,20 @@ final class ArticlesTable: DatabaseTable { // MARK: - Fetching Articles for Feed - func fetchArticles(_ webFeedID: String) throws -> Set
{ - return try fetchArticles{ self.fetchArticlesForFeedID(webFeedID, $0) } + func fetchArticles(_ feedID: String) throws -> Set
{ + return try fetchArticles{ self.fetchArticlesForFeedID(feedID, $0) } } - func fetchArticlesAsync(_ webFeedID: String, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticlesForFeedID(webFeedID, $0) }, completion) + func fetchArticlesAsync(_ feedID: String, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchArticlesForFeedID(feedID, $0) }, completion) } - func fetchArticles(_ webFeedIDs: Set) throws -> Set
{ - return try fetchArticles{ self.fetchArticles(webFeedIDs, $0) } + func fetchArticles(_ feedIDs: Set) throws -> Set
{ + return try fetchArticles{ self.fetchArticles(feedIDs, $0) } } - func fetchArticlesAsync(_ webFeedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticles(webFeedIDs, $0) }, completion) + func fetchArticlesAsync(_ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchArticles(feedIDs, $0) }, completion) } // MARK: - Fetching Articles by articleID @@ -76,36 +76,36 @@ final class ArticlesTable: DatabaseTable { // MARK: - Fetching Unread Articles - func fetchUnreadArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ - return try fetchArticles{ self.fetchUnreadArticles(webFeedIDs, limit, $0) } + func fetchUnreadArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ + return try fetchArticles{ self.fetchUnreadArticles(feedIDs, limit, $0) } } - func fetchUnreadArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchUnreadArticles(webFeedIDs, limit, $0) }, completion) + func fetchUnreadArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchUnreadArticles(feedIDs, limit, $0) }, completion) } // MARK: - Fetching Today Articles - func fetchArticlesSince(_ webFeedIDs: Set, _ cutoffDate: Date, _ limit: Int?) throws -> Set
{ - return try fetchArticles{ self.fetchArticlesSince(webFeedIDs, cutoffDate, limit, $0) } + func fetchArticlesSince(_ feedIDs: Set, _ cutoffDate: Date, _ limit: Int?) throws -> Set
{ + return try fetchArticles{ self.fetchArticlesSince(feedIDs, cutoffDate, limit, $0) } } - func fetchArticlesSinceAsync(_ webFeedIDs: Set, _ cutoffDate: Date, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticlesSince(webFeedIDs, cutoffDate, limit, $0) }, completion) + func fetchArticlesSinceAsync(_ feedIDs: Set, _ cutoffDate: Date, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchArticlesSince(feedIDs, cutoffDate, limit, $0) }, completion) } // MARK: - Fetching Starred Articles - func fetchStarredArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ - return try fetchArticles{ self.fetchStarredArticles(webFeedIDs, limit, $0) } + func fetchStarredArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ + return try fetchArticles{ self.fetchStarredArticles(feedIDs, limit, $0) } } - func fetchStarredArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchStarredArticles(webFeedIDs, limit, $0) }, completion) + func fetchStarredArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchStarredArticles(feedIDs, limit, $0) }, completion) } - func fetchStarredArticlesCount(_ webFeedIDs: Set) throws -> Int { - return try fetchArticlesCount{ self.fetchStarredArticlesCount(webFeedIDs, $0) } + func fetchStarredArticlesCount(_ feedIDs: Set) throws -> Int { + return try fetchArticlesCount{ self.fetchStarredArticlesCount(feedIDs, $0) } } // MARK: - Fetching Search Articles @@ -129,9 +129,9 @@ final class ArticlesTable: DatabaseTable { return articles } - func fetchArticlesMatching(_ searchString: String, _ webFeedIDs: Set) throws -> Set
{ + func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set) throws -> Set
{ var articles = try fetchArticlesMatching(searchString) - articles = articles.filter{ webFeedIDs.contains($0.webFeedID) } + articles = articles.filter{ feedIDs.contains($0.feedID) } return articles } @@ -141,8 +141,8 @@ final class ArticlesTable: DatabaseTable { return articles } - func fetchArticlesMatchingAsync(_ searchString: String, _ webFeedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticlesMatching(searchString, webFeedIDs, $0) }, completion) + func fetchArticlesMatchingAsync(_ searchString: String, _ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchArticlesMatching(searchString, feedIDs, $0) }, completion) } func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { @@ -195,7 +195,7 @@ final class ArticlesTable: DatabaseTable { // MARK: - Updating and Deleting - func update(_ parsedItems: Set, _ webFeedID: String, _ deleteOlder: Bool, _ completion: @escaping UpdateArticlesCompletionBlock) { + func update(_ parsedItems: Set, _ feedID: String, _ deleteOlder: Bool, _ completion: @escaping UpdateArticlesCompletionBlock) { precondition(retentionStyle == .feedBased) if parsedItems.isEmpty { callUpdateArticlesCompletionBlock(nil, nil, nil, completion) @@ -220,13 +220,13 @@ final class ArticlesTable: DatabaseTable { let (statusesDictionary, _) = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, false, database) //1 assert(statusesDictionary.count == articleIDs.count) - let incomingArticles = Article.articlesWithParsedItems(parsedItems, webFeedID, self.accountID, statusesDictionary) //2 + let incomingArticles = Article.articlesWithParsedItems(parsedItems, feedID, self.accountID, statusesDictionary) //2 if incomingArticles.isEmpty { self.callUpdateArticlesCompletionBlock(nil, nil, nil, completion) return } - let fetchedArticles = self.fetchArticlesForFeedID(webFeedID, database) //4 + let fetchedArticles = self.fetchArticlesForFeedID(feedID, database) //4 let fetchedArticlesDictionary = fetchedArticles.dictionary() let newArticles = self.findAndSaveNewArticles(incomingArticles, fetchedArticlesDictionary, database) //5 @@ -275,9 +275,9 @@ final class ArticlesTable: DatabaseTable { } } - func update(_ webFeedIDsAndItems: [String: Set], _ read: Bool, _ completion: @escaping UpdateArticlesCompletionBlock) { + func update(_ feedIDsAndItems: [String: Set], _ read: Bool, _ completion: @escaping UpdateArticlesCompletionBlock) { precondition(retentionStyle == .syncSystem) - if webFeedIDsAndItems.isEmpty { + if feedIDsAndItems.isEmpty { callUpdateArticlesCompletionBlock(nil, nil, nil, completion) return } @@ -295,14 +295,14 @@ final class ArticlesTable: DatabaseTable { func makeDatabaseCalls(_ database: FMDatabase) { var articleIDs = Set() - for (_, parsedItems) in webFeedIDsAndItems { + for (_, parsedItems) in feedIDsAndItems { articleIDs.formUnion(parsedItems.articleIDs()) } let (statusesDictionary, _) = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, read, database) //1 assert(statusesDictionary.count == articleIDs.count) - let allIncomingArticles = Article.articlesWithWebFeedIDsAndItems(webFeedIDsAndItems, self.accountID, statusesDictionary) //2 + let allIncomingArticles = Article.articlesWithFeedIDsAndItems(feedIDsAndItems, self.accountID, statusesDictionary) //2 if allIncomingArticles.isEmpty { self.callUpdateArticlesCompletionBlock(nil, nil, nil, completion) return @@ -371,9 +371,9 @@ final class ArticlesTable: DatabaseTable { // MARK: - Unread Counts - func fetchUnreadCount(_ webFeedIDs: Set, _ since: Date, _ completion: @escaping SingleUnreadCountCompletionBlock) { + func fetchUnreadCount(_ feedIDs: Set, _ since: Date, _ completion: @escaping SingleUnreadCountCompletionBlock) { // Get unread count for today, for instance. - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { completion(.success(0)) return } @@ -381,11 +381,11 @@ final class ArticlesTable: DatabaseTable { queue.runInDatabase { databaseResult in func makeDatabaseCalls(_ database: FMDatabase) { - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and (datePublished > ? or (datePublished is null and dateArrived > ?)) and read=0;" var parameters = [Any]() - parameters += Array(webFeedIDs) as [Any] + parameters += Array(feedIDs) as [Any] parameters += [since] as [Any] parameters += [since] as [Any] @@ -407,8 +407,8 @@ final class ArticlesTable: DatabaseTable { } } - func fetchStarredAndUnreadCount(_ webFeedIDs: Set, _ completion: @escaping SingleUnreadCountCompletionBlock) { - if webFeedIDs.isEmpty { + func fetchStarredAndUnreadCount(_ feedIDs: Set, _ completion: @escaping SingleUnreadCountCompletionBlock) { + if feedIDs.isEmpty { completion(.success(0)) return } @@ -416,9 +416,9 @@ final class ArticlesTable: DatabaseTable { queue.runInDatabase { databaseResult in func makeDatabaseCalls(_ database: FMDatabase) { - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and read=0 and starred=1;" - let parameters = Array(webFeedIDs) as [Any] + let parameters = Array(feedIDs) as [Any] let unreadCount = self.numberWithSQLAndParameters(sql, parameters, in: database) @@ -609,16 +609,16 @@ final class ArticlesTable: DatabaseTable { /// Delete articles from feeds that are no longer in the current set of subscribed-to feeds. /// This deletes from the articles and articleStatuses tables, /// and, via a trigger, it also deletes from the search index. - func deleteArticlesNotInSubscribedToFeedIDs(_ webFeedIDs: Set) { - if webFeedIDs.isEmpty { + func deleteArticlesNotInSubscribedToFeedIDs(_ feedIDs: Set) { + if feedIDs.isEmpty { return } queue.runInDatabase { databaseResult in func makeDatabaseCalls(_ database: FMDatabase) { - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let sql = "select articleID from articles where feedID not in \(placeholders);" - let parameters = Array(webFeedIDs) as [Any] + let parameters = Array(feedIDs) as [Any] guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else { return } @@ -820,24 +820,24 @@ private extension ArticlesTable { return articlesWithResultSet(resultSet, database) } - func fetchArticles(_ webFeedIDs: Set, _ database: FMDatabase) -> Set
{ + func fetchArticles(_ feedIDs: Set, _ database: FMDatabase) -> Set
{ // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and read=0 - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return Set
() } - let parameters = webFeedIDs.map { $0 as AnyObject } - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let whereClause = "feedID in \(placeholders)" return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchUnreadArticles(_ webFeedIDs: Set, _ limit: Int?, _ database: FMDatabase) -> Set
{ + func fetchUnreadArticles(_ feedIDs: Set, _ limit: Int?, _ database: FMDatabase) -> Set
{ // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and read=0 - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return Set
() } - let parameters = webFeedIDs.map { $0 as AnyObject } - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! var whereClause = "feedID in \(placeholders) and read=0" if let limit = limit { whereClause.append(" order by coalesce(datePublished, dateModified, dateArrived) desc limit \(limit)") @@ -845,8 +845,8 @@ private extension ArticlesTable { return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchArticlesForFeedID(_ webFeedID: String, _ database: FMDatabase) -> Set
{ - return fetchArticlesWithWhereClause(database, whereClause: "articles.feedID = ?", parameters: [webFeedID as AnyObject]) + func fetchArticlesForFeedID(_ feedID: String, _ database: FMDatabase) -> Set
{ + return fetchArticlesWithWhereClause(database, whereClause: "articles.feedID = ?", parameters: [feedID as AnyObject]) } func fetchArticles(articleIDs: Set, _ database: FMDatabase) -> Set
{ @@ -859,15 +859,15 @@ private extension ArticlesTable { return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchArticlesSince(_ webFeedIDs: Set, _ cutoffDate: Date, _ limit: Int?, _ database: FMDatabase) -> Set
{ + func fetchArticlesSince(_ feedIDs: Set, _ cutoffDate: Date, _ limit: Int?, _ database: FMDatabase) -> Set
{ // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and (datePublished > ? || (datePublished is null and dateArrived > ?) // // datePublished may be nil, so we fall back to dateArrived. - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return Set
() } - let parameters = webFeedIDs.map { $0 as AnyObject } + [cutoffDate as AnyObject, cutoffDate as AnyObject] - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + [cutoffDate as AnyObject, cutoffDate as AnyObject] + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! var whereClause = "feedID in \(placeholders) and (datePublished > ? or (datePublished is null and dateArrived > ?))" if let limit = limit { whereClause.append(" order by coalesce(datePublished, dateModified, dateArrived) desc limit \(limit)") @@ -875,13 +875,13 @@ private extension ArticlesTable { return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchStarredArticles(_ webFeedIDs: Set, _ limit: Int?, _ database: FMDatabase) -> Set
{ + func fetchStarredArticles(_ feedIDs: Set, _ limit: Int?, _ database: FMDatabase) -> Set
{ // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and starred=1; - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return Set
() } - let parameters = webFeedIDs.map { $0 as AnyObject } - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! var whereClause = "feedID in \(placeholders) and starred=1" if let limit = limit { whereClause.append(" order by coalesce(datePublished, dateModified, dateArrived) desc limit \(limit)") @@ -889,21 +889,21 @@ private extension ArticlesTable { return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchStarredArticlesCount(_ webFeedIDs: Set, _ database: FMDatabase) -> Int { + func fetchStarredArticlesCount(_ feedIDs: Set, _ database: FMDatabase) -> Int { // select count from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and starred=1; - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return 0 } - let parameters = webFeedIDs.map { $0 as AnyObject } - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let whereClause = "feedID in \(placeholders) and starred=1" return fetchArticleCountsWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchArticlesMatching(_ searchString: String, _ webFeedIDs: Set, _ database: FMDatabase) -> Set
{ + func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set, _ database: FMDatabase) -> Set
{ let articles = fetchArticlesMatching(searchString, database) // TODO: include the feedIDs in the SQL rather than filtering here. - return articles.filter{ webFeedIDs.contains($0.webFeedID) } + return articles.filter{ feedIDs.contains($0.feedID) } } func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set, _ database: FMDatabase) -> Set
{ diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/Article+Database.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/Article+Database.swift index e94a8969d..9660d3187 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/Article+Database.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/Article+Database.swift @@ -19,7 +19,7 @@ extension Article { assertionFailure("Expected articleID.") return nil } - guard let webFeedID = row.string(forColumn: DatabaseKey.feedID) else { + guard let feedID = row.string(forColumn: DatabaseKey.feedID) else { assertionFailure("Expected feedID.") return nil } @@ -39,10 +39,10 @@ extension Article { let datePublished = row.date(forColumn: DatabaseKey.datePublished) let dateModified = row.date(forColumn: DatabaseKey.dateModified) - self.init(accountID: accountID, articleID: articleID, webFeedID: webFeedID, uniqueID: uniqueID, title: title, contentHTML: contentHTML, contentText: contentText, markdown: markdown, url: url, externalURL: externalURL, summary: summary, imageURL: imageURL, datePublished: datePublished, dateModified: dateModified, authors: nil, status: status) + self.init(accountID: accountID, articleID: articleID, feedID: feedID, uniqueID: uniqueID, title: title, contentHTML: contentHTML, contentText: contentText, markdown: markdown, url: url, externalURL: externalURL, summary: summary, imageURL: imageURL, datePublished: datePublished, dateModified: dateModified, authors: nil, status: status) } - convenience init(parsedItem: ParsedItem, maximumDateAllowed: Date, accountID: String, webFeedID: String, status: ArticleStatus) { + convenience init(parsedItem: ParsedItem, maximumDateAllowed: Date, accountID: String, feedID: String, status: ArticleStatus) { let authors = Author.authorsWithParsedAuthors(parsedItem.authors) // Deal with future datePublished and dateModified dates. @@ -59,7 +59,7 @@ extension Article { dateModified = nil } - self.init(accountID: accountID, articleID: parsedItem.syncServiceID, webFeedID: webFeedID, uniqueID: parsedItem.uniqueID, title: parsedItem.title, contentHTML: parsedItem.contentHTML, contentText: parsedItem.contentText, markdown: parsedItem.markdown, url: parsedItem.url, externalURL: parsedItem.externalURL, summary: parsedItem.summary, imageURL: parsedItem.imageURL, datePublished: datePublished, dateModified: dateModified, authors: authors, status: status) + self.init(accountID: accountID, articleID: parsedItem.syncServiceID, feedID: feedID, uniqueID: parsedItem.uniqueID, title: parsedItem.title, contentHTML: parsedItem.contentHTML, contentText: parsedItem.contentText, markdown: parsedItem.markdown, url: parsedItem.url, externalURL: parsedItem.externalURL, summary: parsedItem.summary, imageURL: parsedItem.imageURL, datePublished: datePublished, dateModified: dateModified, authors: authors, status: status) } private func addPossibleStringChangeWithKeyPath(_ comparisonKeyPath: KeyPath, _ otherArticle: Article, _ key: String, _ dictionary: inout DatabaseDictionary) { @@ -72,7 +72,7 @@ extension Article { if authors.isEmpty { return self } - return Article(accountID: self.accountID, articleID: self.articleID, webFeedID: self.webFeedID, uniqueID: self.uniqueID, title: self.title, contentHTML: self.contentHTML, contentText: self.contentText, markdown: self.markdown, url: self.rawLink, externalURL: self.rawExternalLink, summary: self.summary, imageURL: self.rawImageLink, datePublished: self.datePublished, dateModified: self.dateModified, authors: authors, status: self.status) + return Article(accountID: self.accountID, articleID: self.articleID, feedID: self.feedID, uniqueID: self.uniqueID, title: self.title, contentHTML: self.contentHTML, contentText: self.contentText, markdown: self.markdown, url: self.rawLink, externalURL: self.rawExternalLink, summary: self.summary, imageURL: self.rawImageLink, datePublished: self.datePublished, dateModified: self.dateModified, authors: authors, status: self.status) } func changesFrom(_ existingArticle: Article) -> DatabaseDictionary? { @@ -118,22 +118,22 @@ extension Article { return Date().addingTimeInterval(60 * 60 * 24) // Allow dates up to about 24 hours ahead of now } - static func articlesWithWebFeedIDsAndItems(_ webFeedIDsAndItems: [String: Set], _ accountID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set
{ + static func articlesWithFeedIDsAndItems(_ feedIDsAndItems: [String: Set], _ accountID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set
{ let maximumDateAllowed = _maximumDateAllowed() var feedArticles = Set
() - for (webFeedID, parsedItems) in webFeedIDsAndItems { + for (feedID, parsedItems) in feedIDsAndItems { for parsedItem in parsedItems { let status = statusesDictionary[parsedItem.articleID]! - let article = Article(parsedItem: parsedItem, maximumDateAllowed: maximumDateAllowed, accountID: accountID, webFeedID: webFeedID, status: status) + let article = Article(parsedItem: parsedItem, maximumDateAllowed: maximumDateAllowed, accountID: accountID, feedID: feedID, status: status) feedArticles.insert(article) } } return feedArticles } - static func articlesWithParsedItems(_ parsedItems: Set, _ webFeedID: String, _ accountID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set
{ + static func articlesWithParsedItems(_ parsedItems: Set, _ feedID: String, _ accountID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set
{ let maximumDateAllowed = _maximumDateAllowed() - return Set(parsedItems.map{ Article(parsedItem: $0, maximumDateAllowed: maximumDateAllowed, accountID: accountID, webFeedID: webFeedID, status: statusesDictionary[$0.articleID]!) }) + return Set(parsedItems.map{ Article(parsedItem: $0, maximumDateAllowed: maximumDateAllowed, accountID: accountID, feedID: feedID, status: statusesDictionary[$0.articleID]!) }) } } @@ -143,7 +143,7 @@ extension Article: @retroactive DatabaseObject { var d = DatabaseDictionary() d[DatabaseKey.articleID] = articleID - d[DatabaseKey.feedID] = webFeedID + d[DatabaseKey.feedID] = feedID d[DatabaseKey.uniqueID] = uniqueID if let title = title { diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/ParsedArticle+Database.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/ParsedArticle+Database.swift index e59539d11..271876057 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/ParsedArticle+Database.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/ParsedArticle+Database.swift @@ -17,6 +17,6 @@ extension ParsedItem { return s } // Must be same calculation as for Article. - return Article.calculatedArticleID(webFeedID: feedURL, uniqueID: uniqueID) + return Article.calculatedArticleID(feedID: feedURL, uniqueID: uniqueID) } } diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchAllUnreadCountsOperation.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchAllUnreadCountsOperation.swift index bad3e2e1f..2b49db38f 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchAllUnreadCountsOperation.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchAllUnreadCountsOperation.swift @@ -63,8 +63,8 @@ private extension FetchAllUnreadCountsOperation { return } let unreadCount = resultSet.long(forColumnIndex: 1) - if let webFeedID = resultSet.string(forColumnIndex: 0) { - unreadCountDictionary[webFeedID] = unreadCount + if let feedID = resultSet.string(forColumnIndex: 0) { + unreadCountDictionary[feedID] = unreadCount } } resultSet.close() diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchFeedUnreadCountOperation.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchFeedUnreadCountOperation.swift index 03c6cf793..d7728fb26 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchFeedUnreadCountOperation.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchFeedUnreadCountOperation.swift @@ -25,10 +25,10 @@ public final class FetchFeedUnreadCountOperation: MainThreadOperation { private let queue: DatabaseQueue private let cutoffDate: Date - private let webFeedID: String + private let feedID: String - init(webFeedID: String, databaseQueue: DatabaseQueue, cutoffDate: Date) { - self.webFeedID = webFeedID + init(feedID: String, databaseQueue: DatabaseQueue, cutoffDate: Date) { + self.feedID = feedID self.queue = databaseQueue self.cutoffDate = cutoffDate } @@ -55,7 +55,7 @@ private extension FetchFeedUnreadCountOperation { func fetchUnreadCount(_ database: FMDatabase) { let sql = "select count(*) from articles natural join statuses where feedID=? and read=0;" - guard let resultSet = database.executeQuery(sql, withArgumentsIn: [webFeedID]) else { + guard let resultSet = database.executeQuery(sql, withArgumentsIn: [feedID]) else { informOperationDelegateOfCompletion() return } diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchUnreadCountsForFeedsOperation.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchUnreadCountsForFeedsOperation.swift index 3a560a94d..c3bcff808 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchUnreadCountsForFeedsOperation.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchUnreadCountsForFeedsOperation.swift @@ -24,10 +24,10 @@ public final class FetchUnreadCountsForFeedsOperation: MainThreadOperation { public var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock? private let queue: DatabaseQueue - private let webFeedIDs: Set + private let feedIDs: Set - init(webFeedIDs: Set, databaseQueue: DatabaseQueue) { - self.webFeedIDs = webFeedIDs + init(feedIDs: Set, databaseQueue: DatabaseQueue) { + self.feedIDs = feedIDs self.queue = databaseQueue } @@ -51,10 +51,10 @@ public final class FetchUnreadCountsForFeedsOperation: MainThreadOperation { private extension FetchUnreadCountsForFeedsOperation { func fetchUnreadCounts(_ database: FMDatabase) { - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let sql = "select distinct feedID, count(*) from articles natural join statuses where feedID in \(placeholders) and read=0 group by feedID;" - let parameters = Array(webFeedIDs) as [Any] + let parameters = Array(feedIDs) as [Any] guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else { informOperationDelegateOfCompletion() @@ -74,8 +74,8 @@ private extension FetchUnreadCountsForFeedsOperation { return } let unreadCount = resultSet.long(forColumnIndex: 1) - if let webFeedID = resultSet.string(forColumnIndex: 0) { - unreadCountDictionary[webFeedID] = unreadCount + if let feedID = resultSet.string(forColumnIndex: 0) { + unreadCountDictionary[feedID] = unreadCount } } resultSet.close() diff --git a/Shared/Activity/ActivityManager.swift b/Shared/Activity/ActivityManager.swift index 926902734..582cad871 100644 --- a/Shared/Activity/ActivityManager.swift +++ b/Shared/Activity/ActivityManager.swift @@ -40,7 +40,7 @@ final class ActivityManager { } init() { - NotificationCenter.default.addObserver(self, selector: #selector(webFeedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) } func invalidateCurrentActivities() { @@ -54,8 +54,8 @@ final class ActivityManager { selectingActivity = makeSelectFeedActivity(sidebarItem: sidebarItem) - if let webFeed = sidebarItem as? WebFeed { - updateSelectingActivityFeedSearchAttributes(with: webFeed) + if let feed = sidebarItem as? Feed { + updateSelectingActivityFeedSearchAttributes(with: feed) } donate(selectingActivity!) @@ -117,8 +117,8 @@ final class ActivityManager { } } - for webFeed in account.flattenedWebFeeds() { - ids.append(contentsOf: identifiers(for: webFeed)) + for feed in account.flattenedFeeds() { + ids.append(contentsOf: identifiers(for: feed)) } CSSearchableIndex.default().deleteSearchableItems(withIdentifiers: ids) @@ -128,31 +128,31 @@ final class ActivityManager { var ids = [String]() ids.append(identifier(for: folder)) - for webFeed in folder.flattenedWebFeeds() { - ids.append(contentsOf: identifiers(for: webFeed)) + for feed in folder.flattenedFeeds() { + ids.append(contentsOf: identifiers(for: feed)) } CSSearchableIndex.default().deleteSearchableItems(withIdentifiers: ids) } - static func cleanUp(_ webFeed: WebFeed) { - CSSearchableIndex.default().deleteSearchableItems(withIdentifiers: identifiers(for: webFeed)) + static func cleanUp(_ feed: Feed) { + CSSearchableIndex.default().deleteSearchableItems(withIdentifiers: identifiers(for: feed)) } #endif - @objc func webFeedIconDidBecomeAvailable(_ note: Notification) { - guard let webFeed = note.userInfo?[UserInfoKey.webFeed] as? WebFeed, let activityFeedId = selectingActivity?.userInfo?[ArticlePathKey.webFeedID] as? String else { + @objc func feedIconDidBecomeAvailable(_ note: Notification) { + guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed, let activityFeedId = selectingActivity?.userInfo?[ArticlePathKey.feedID] as? String else { return } #if os(iOS) - if let article = readingArticle, activityFeedId == article.webFeedID { + if let article = readingArticle, activityFeedId == article.feedID { updateReadArticleSearchAttributes(with: article) } #endif - if activityFeedId == webFeed.webFeedID { - updateSelectingActivityFeedSearchAttributes(with: webFeed) + if activityFeedId == feed.feedID { + updateSelectingActivityFeedSearchAttributes(with: feed) } } @@ -236,7 +236,7 @@ private extension ActivityManager { #endif func makeKeywords(_ article: Article) -> [String] { - let feedNameKeywords = makeKeywords(article.webFeed?.nameForDisplay) + let feedNameKeywords = makeKeywords(article.feed?.nameForDisplay) let articleTitleKeywords = makeKeywords(ArticleStringFormatter.truncatedTitle(article)) return feedNameKeywords + articleTitleKeywords } @@ -245,7 +245,7 @@ private extension ActivityManager { return value?.components(separatedBy: " ").filter { $0.count > 2 } ?? [] } - func updateSelectingActivityFeedSearchAttributes(with feed: WebFeed) { + func updateSelectingActivityFeedSearchAttributes(with feed: Feed) { let attributeSet = CSSearchableItemAttributeSet(contentType: UTType.compositeContent) attributeSet.title = feed.nameForDisplay @@ -278,15 +278,15 @@ private extension ActivityManager { return "account_\(folder.account!.accountID)_folder_\(folder.nameForDisplay)" } - static func identifier(for feed: WebFeed) -> String { - return "account_\(feed.account!.accountID)_feed_\(feed.webFeedID)" + static func identifier(for feed: Feed) -> String { + return "account_\(feed.account!.accountID)_feed_\(feed.feedID)" } static func identifier(for article: Article) -> String { - return "account_\(article.accountID)_feed_\(article.webFeedID)_article_\(article.articleID)" + return "account_\(article.accountID)_feed_\(article.feedID)_article_\(article.articleID)" } - static func identifiers(for feed: WebFeed) -> [String] { + static func identifiers(for feed: Feed) -> [String] { var ids = [String]() ids.append(identifier(for: feed)) if let articles = try? feed.fetchArticles() { diff --git a/Shared/Article Rendering/ArticleRenderer.swift b/Shared/Article Rendering/ArticleRenderer.swift index 58f8c938d..9513a8fc9 100644 --- a/Shared/Article Rendering/ArticleRenderer.swift +++ b/Shared/Article Rendering/ArticleRenderer.swift @@ -241,8 +241,8 @@ private extension ArticleRenderer { d["dateline_style"] = "articleDateline" } - d["feed_link_title"] = article.webFeed?.nameForDisplay ?? "" - d["feed_link"] = article.webFeed?.homePageURL ?? "" + d["feed_link_title"] = article.feed?.nameForDisplay ?? "" + d["feed_link"] = article.feed?.homePageURL ?? "" d["byline"] = byline() @@ -261,7 +261,7 @@ private extension ArticleRenderer { } func byline() -> String { - guard let authors = article?.authors ?? article?.webFeed?.authors, !authors.isEmpty else { + guard let authors = article?.authors ?? article?.feed?.authors, !authors.isEmpty else { return "" } @@ -269,7 +269,7 @@ private extension ArticleRenderer { // This code assumes that multiple authors would never match the feed name so that // if there feed owner has an article co-author all authors are given the byline. if authors.count == 1, let author = authors.first { - if author.name == article?.webFeed?.nameForDisplay { + if author.name == article?.feed?.nameForDisplay { return "" } } @@ -333,10 +333,10 @@ private extension Article { var baseURL: URL? { var s = link if s == nil { - s = webFeed?.homePageURL + s = feed?.homePageURL } if s == nil { - s = webFeed?.url + s = feed?.url } guard let urlString = s else { diff --git a/Shared/Commands/DeleteCommand.swift b/Shared/Commands/DeleteCommand.swift index 991b7b430..9e37fe69f 100644 --- a/Shared/Commands/DeleteCommand.swift +++ b/Shared/Commands/DeleteCommand.swift @@ -77,7 +77,7 @@ final class DeleteCommand: UndoableCommand { } for node in nodes { - if let _ = node.representedObject as? WebFeed { + if let _ = node.representedObject as? Feed { continue } if let _ = node.representedObject as? Folder { @@ -98,7 +98,7 @@ private struct SidebarItemSpecifier { private weak var account: Account? private let parentFolder: Folder? private let folder: Folder? - private let webFeed: WebFeed? + private let feed: Feed? private let path: ContainerPath private let errorHandler: (Error) -> () @@ -118,13 +118,13 @@ private struct SidebarItemSpecifier { self.parentFolder = node.parentFolder() - if let webFeed = node.representedObject as? WebFeed { - self.webFeed = webFeed + if let feed = node.representedObject as? Feed { + self.feed = feed self.folder = nil - account = webFeed.account + account = feed.account } else if let folder = node.representedObject as? Folder { - self.webFeed = nil + self.feed = nil self.folder = folder account = folder.account } @@ -144,15 +144,15 @@ private struct SidebarItemSpecifier { func delete(completion: @escaping () -> Void) { - if let webFeed = webFeed { - + if let feed = feed { + guard let container = path.resolveContainer() else { completion() return } BatchUpdate.shared.start() - account?.removeWebFeed(webFeed, from: container) { result in + account?.removeFeed(feed, from: container) { result in BatchUpdate.shared.end() completion() self.checkResult(result) @@ -172,22 +172,22 @@ private struct SidebarItemSpecifier { func restore() { - if let _ = webFeed { - restoreWebFeed() + if let _ = feed { + restoreFeed() } else if let _ = folder { restoreFolder() } } - private func restoreWebFeed() { + private func restoreFeed() { - guard let account = account, let feed = webFeed, let container = path.resolveContainer() else { + guard let account = account, let feed = feed, let container = path.resolveContainer() else { return } BatchUpdate.shared.start() - account.restoreWebFeed(feed, container: container) { result in + account.restoreFeed(feed, container: container) { result in BatchUpdate.shared.end() self.checkResult(result) } @@ -271,7 +271,7 @@ private struct DeleteActionName { var numberOfFolders = 0 for node in nodes { - if let _ = node.representedObject as? WebFeed { + if let _ = node.representedObject as? Feed { numberOfFeeds += 1 } else if let _ = node.representedObject as? Folder { diff --git a/Shared/ExtensionPoints/SendToMarsEditCommand.swift b/Shared/ExtensionPoints/SendToMarsEditCommand.swift index 484398a87..49576b1c7 100644 --- a/Shared/ExtensionPoints/SendToMarsEditCommand.swift +++ b/Shared/ExtensionPoints/SendToMarsEditCommand.swift @@ -56,7 +56,7 @@ private extension SendToMarsEditCommand { let body = article.contentHTML ?? article.contentText ?? article.summary let authorName = article.authors?.first?.name - let sender = SendToBlogEditorApp(targetDescriptor: targetDescriptor, title: article.title, body: body, summary: article.summary, link: article.externalLink, permalink: article.link, subject: nil, creator: authorName, commentsURL: nil, guid: article.uniqueID, sourceName: article.webFeed?.nameForDisplay, sourceHomeURL: article.webFeed?.homePageURL, sourceFeedURL: article.webFeed?.url) + let sender = SendToBlogEditorApp(targetDescriptor: targetDescriptor, title: article.title, body: body, summary: article.summary, link: article.externalLink, permalink: article.link, subject: nil, creator: authorName, commentsURL: nil, guid: article.uniqueID, sourceName: article.feed?.nameForDisplay, sourceHomeURL: article.feed?.homePageURL, sourceFeedURL: article.feed?.url) let _ = sender.send() } diff --git a/Shared/ExtensionPoints/SendToMicroBlogCommand.swift b/Shared/ExtensionPoints/SendToMicroBlogCommand.swift index 4d6fe3bd7..342bec319 100644 --- a/Shared/ExtensionPoints/SendToMicroBlogCommand.swift +++ b/Shared/ExtensionPoints/SendToMicroBlogCommand.swift @@ -68,10 +68,10 @@ private extension Article { // Feed name, or feed name + author name (if author is specified per-article). // Includes trailing space. - if let feedName = webFeed?.nameForDisplay, let authorName = authors?.first?.name { + if let feedName = feed?.nameForDisplay, let authorName = authors?.first?.name { return feedName + ", " + authorName + ": " } - if let feedName = webFeed?.nameForDisplay { + if let feedName = feed?.nameForDisplay { return feedName + ": " } return "" diff --git a/Shared/Extensions/AddWebFeedDefaultContainer.swift b/Shared/Extensions/AddFeedDefaultContainer.swift similarity index 61% rename from Shared/Extensions/AddWebFeedDefaultContainer.swift rename to Shared/Extensions/AddFeedDefaultContainer.swift index 65cb31a3f..6bf7fa880 100644 --- a/Shared/Extensions/AddWebFeedDefaultContainer.swift +++ b/Shared/Extensions/AddFeedDefaultContainer.swift @@ -1,5 +1,5 @@ // -// AddWebFeedDefaultContainer.swift +// AddFeedDefaultContainer.swift // NetNewsWire-iOS // // Created by Maurice Parker on 11/16/19. @@ -9,12 +9,12 @@ import Foundation import Account -struct AddWebFeedDefaultContainer { +struct AddFeedDefaultContainer { static var defaultContainer: Container? { - if let accountID = AppDefaults.shared.addWebFeedAccountID, let account = AccountManager.shared.activeAccounts.first(where: { $0.accountID == accountID }) { - if let folderName = AppDefaults.shared.addWebFeedFolderName, let folder = account.existingFolder(withDisplayName: folderName) { + if let accountID = AppDefaults.shared.addFeedAccountID, let account = AccountManager.shared.activeAccounts.first(where: { $0.accountID == accountID }) { + if let folderName = AppDefaults.shared.addFeedFolderName, let folder = account.existingFolder(withDisplayName: folderName) { return folder } else { return substituteContainerIfNeeded(account: account) @@ -28,11 +28,11 @@ struct AddWebFeedDefaultContainer { } static func saveDefaultContainer(_ container: Container) { - AppDefaults.shared.addWebFeedAccountID = container.account?.accountID + AppDefaults.shared.addFeedAccountID = container.account?.accountID if let folder = container as? Folder { - AppDefaults.shared.addWebFeedFolderName = folder.nameForDisplay + AppDefaults.shared.addFeedFolderName = folder.nameForDisplay } else { - AppDefaults.shared.addWebFeedFolderName = nil + AppDefaults.shared.addFeedFolderName = nil } } diff --git a/Shared/Extensions/ArticleUtilities.swift b/Shared/Extensions/ArticleUtilities.swift index 2deaa3f52..280c51563 100644 --- a/Shared/Extensions/ArticleUtilities.swift +++ b/Shared/Extensions/ArticleUtilities.swift @@ -42,8 +42,8 @@ private func accountAndArticlesDictionary(_ articles: Set
) -> [String: extension Article { - var webFeed: WebFeed? { - return account?.existingWebFeed(withWebFeedID: webFeedID) + var feed: Feed? { + return account?.existingFeed(withFeedID: feedID) } var url: URL? { @@ -121,11 +121,11 @@ extension Article { return IconImageCache.shared.imageForArticle(self) } - func iconImageUrl(webFeed: WebFeed) -> URL? { + func iconImageUrl(feed: Feed) -> URL? { if let image = iconImage() { let fm = FileManager.default var path = fm.urls(for: .cachesDirectory, in: .userDomainMask)[0] - let feedID = webFeed.webFeedID.replacingOccurrences(of: "/", with: "_") + let feedID = feed.feedID.replacingOccurrences(of: "/", with: "_") path.appendPathComponent(feedID + "_smallIcon.png") fm.createFile(atPath: path.path, contents: image.image.dataRepresentation()!, attributes: nil) return path @@ -135,7 +135,7 @@ extension Article { } func byline() -> String { - guard let authors = authors ?? webFeed?.authors, !authors.isEmpty else { + guard let authors = authors ?? feed?.authors, !authors.isEmpty else { return "" } @@ -143,7 +143,7 @@ extension Article { // This code assumes that multiple authors would never match the feed name so that // if there feed owner has an article co-author all authors are given the byline. if authors.count == 1, let author = authors.first { - if author.name == webFeed?.nameForDisplay { + if author.name == feed?.nameForDisplay { return "" } } @@ -189,7 +189,7 @@ extension Article { struct ArticlePathKey { static let accountID = "accountID" static let accountName = "accountName" - static let webFeedID = "webFeedID" + static let feedID = "feedID" static let articleID = "articleID" } @@ -199,7 +199,7 @@ extension Article { return [ ArticlePathKey.accountID: accountID, ArticlePathKey.accountName: account?.nameForDisplay ?? "", - ArticlePathKey.webFeedID: webFeedID, + ArticlePathKey.feedID: feedID, ArticlePathKey.articleID: articleID ] } @@ -211,7 +211,7 @@ extension Article { extension Article: SortableArticle { var sortableName: String { - return webFeed?.name ?? "" + return feed?.name ?? "" } var sortableDate: Date { @@ -222,8 +222,8 @@ extension Article: SortableArticle { return articleID } - var sortableWebFeedID: String { - return webFeedID + var sortableFeedID: String { + return feedID } } diff --git a/Shared/Extensions/SmallIconProvider.swift b/Shared/Extensions/SmallIconProvider.swift index eebf98f19..4a2c0dff8 100644 --- a/Shared/Extensions/SmallIconProvider.swift +++ b/Shared/Extensions/SmallIconProvider.swift @@ -25,7 +25,7 @@ extension Account: SmallIconProvider { } } -extension WebFeed: SmallIconProvider { +extension Feed: SmallIconProvider { var smallIcon: IconImage? { if let iconImage = FaviconDownloader.shared.favicon(for: self) { diff --git a/Shared/Favicons/FaviconDownloader.swift b/Shared/Favicons/FaviconDownloader.swift index 0d9e7ee1a..77be10e6c 100644 --- a/Shared/Favicons/FaviconDownloader.swift +++ b/Shared/Favicons/FaviconDownloader.swift @@ -48,7 +48,7 @@ final class FaviconDownloader { } private let queue: DispatchQueue - private var cache = [WebFeed: IconImage]() // faviconURL: RSImage + private var cache = [Feed: IconImage]() // faviconURL: RSImage struct UserInfoKey { static let faviconURL = "faviconURL" @@ -73,24 +73,24 @@ final class FaviconDownloader { // MARK: - API func resetCache() { - cache = [WebFeed: IconImage]() + cache = [Feed: IconImage]() } - func favicon(for webFeed: WebFeed) -> IconImage? { + func favicon(for feed: Feed) -> IconImage? { assert(Thread.isMainThread) - if shouldSkipDownloadingFavicon(feed: webFeed) { + if shouldSkipDownloadingFavicon(feed: feed) { return nil } - var homePageURL = webFeed.homePageURL - if let faviconURL = webFeed.faviconURL { + var homePageURL = feed.homePageURL + if let faviconURL = feed.faviconURL { return favicon(with: faviconURL, homePageURL: homePageURL) } if homePageURL == nil { // Base homePageURL off feedURL if needed. Won’t always be accurate, but is good enough. - if let feedURL = URL(string: webFeed.url), let scheme = feedURL.scheme, let host = feedURL.host { + if let feedURL = URL(string: feed.url), let scheme = feedURL.scheme, let host = feedURL.host { homePageURL = scheme + "://" + host + "/" } } @@ -101,14 +101,14 @@ final class FaviconDownloader { return nil } - func faviconAsIcon(for webFeed: WebFeed) -> IconImage? { + func faviconAsIcon(for feed: Feed) -> IconImage? { - if let image = cache[webFeed] { + if let image = cache[feed] { return image } - if let iconImage = favicon(for: webFeed) { - cache[webFeed] = iconImage + if let iconImage = favicon(for: feed) { + cache[feed] = iconImage return iconImage } @@ -213,7 +213,7 @@ private extension FaviconDownloader { static let specialCasesToSkip = [SpecialCase.rachelByTheBayHostName, SpecialCase.openRSSOrgHostName] - func shouldSkipDownloadingFavicon(feed: WebFeed) -> Bool { + func shouldSkipDownloadingFavicon(feed: Feed) -> Bool { SpecialCase.urlStringContainSpecialCase(feed.url, Self.specialCasesToSkip) } diff --git a/Shared/Favicons/FaviconGenerator.swift b/Shared/Favicons/FaviconGenerator.swift index 7ff84da50..b405ea195 100644 --- a/Shared/Favicons/FaviconGenerator.swift +++ b/Shared/Favicons/FaviconGenerator.swift @@ -14,16 +14,16 @@ final class FaviconGenerator { private static var faviconGeneratorCache = [String: IconImage]() // feedURL: RSImage - static func favicon(_ webFeed: WebFeed) -> IconImage { + static func favicon(_ feed: Feed) -> IconImage { - if let favicon = FaviconGenerator.faviconGeneratorCache[webFeed.url] { + if let favicon = FaviconGenerator.faviconGeneratorCache[feed.url] { return favicon } - let colorHash = ColorHash(webFeed.url) + let colorHash = ColorHash(feed.url) if let favicon = AppAssets.faviconTemplateImage.maskWithColor(color: colorHash.color.cgColor) { let iconImage = IconImage(favicon, isBackgroundSuppressed: true) - FaviconGenerator.faviconGeneratorCache[webFeed.url] = iconImage + FaviconGenerator.faviconGeneratorCache[feed.url] = iconImage return iconImage } else { return IconImage(AppAssets.faviconTemplateImage, isBackgroundSuppressed: true) diff --git a/Shared/IconImageCache.swift b/Shared/IconImageCache.swift index d1cb0238f..eb99ba2a3 100644 --- a/Shared/IconImageCache.swift +++ b/Shared/IconImageCache.swift @@ -15,7 +15,7 @@ final class IconImageCache { static var shared = IconImageCache() private var smartFeedIconImageCache = [SidebarItemIdentifier: IconImage]() - private var webFeedIconImageCache = [SidebarItemIdentifier: IconImage]() + private var feedIconImageCache = [SidebarItemIdentifier: IconImage]() private var faviconImageCache = [SidebarItemIdentifier: IconImage]() private var smallIconImageCache = [SidebarItemIdentifier: IconImage]() private var authorIconImageCache = [Author: IconImage]() @@ -38,7 +38,7 @@ final class IconImageCache { if let smartFeed = sidebarItem as? PseudoFeed { return imageForSmartFeed(smartFeed, sidebarItemID) } - if let webFeed = sidebarItem as? WebFeed, let iconImage = imageForWebFeed(webFeed, sidebarItemID) { + if let feed = sidebarItem as? Feed, let iconImage = imageForFeed(feed, sidebarItemID) { return iconImage } if let smallIconProvider = sidebarItem as? SmallIconProvider { @@ -52,7 +52,7 @@ final class IconImageCache { if let iconImage = imageForAuthors(article.authors) { return iconImage } - guard let feed = article.webFeed else { + guard let feed = article.feed else { return nil } return imageForFeed(feed) @@ -60,7 +60,7 @@ final class IconImageCache { func emptyCache() { smartFeedIconImageCache = [SidebarItemIdentifier: IconImage]() - webFeedIconImageCache = [SidebarItemIdentifier: IconImage]() + feedIconImageCache = [SidebarItemIdentifier: IconImage]() faviconImageCache = [SidebarItemIdentifier: IconImage]() smallIconImageCache = [SidebarItemIdentifier: IconImage]() authorIconImageCache = [Author: IconImage]() @@ -80,18 +80,18 @@ private extension IconImageCache { return nil } - func imageForWebFeed(_ webFeed: WebFeed, _ feedID: SidebarItemIdentifier) -> IconImage? { - if let iconImage = webFeedIconImageCache[feedID] { + func imageForFeed(_ feed: Feed, _ feedID: SidebarItemIdentifier) -> IconImage? { + if let iconImage = feedIconImageCache[feedID] { return iconImage } - if let iconImage = FeedIconDownloader.shared.icon(for: webFeed) { - webFeedIconImageCache[feedID] = iconImage + if let iconImage = FeedIconDownloader.shared.icon(for: feed) { + feedIconImageCache[feedID] = iconImage return iconImage } if let faviconImage = faviconImageCache[feedID] { return faviconImage } - if let faviconImage = FaviconDownloader.shared.faviconAsIcon(for: webFeed) { + if let faviconImage = FaviconDownloader.shared.faviconAsIcon(for: feed) { faviconImageCache[feedID] = faviconImage return faviconImage } diff --git a/Shared/Images/FeedIconDownloader.swift b/Shared/Images/FeedIconDownloader.swift index 363f4e95f..2ff0de464 100644 --- a/Shared/Images/FeedIconDownloader.swift +++ b/Shared/Images/FeedIconDownloader.swift @@ -24,8 +24,8 @@ public final class FeedIconDownloader { private let imageDownloader = ImageDownloader.shared private static let saveQueue = CoalescingQueue(name: "Cache Save Queue", interval: 1.0) private var homePagesWithNoIconURL = Set() - private var cache = [WebFeed: IconImage]() - private var waitingForFeedURLs = [String: WebFeed]() + private var cache = [Feed: IconImage]() + private var waitingForFeedURLs = [String: Feed]() private var feedURLToIconURLCache = [String: String]() private var feedURLToIconURLCachePath: URL @@ -44,7 +44,7 @@ public final class FeedIconDownloader { NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: imageDownloader) } - func icon(for feed: WebFeed) -> IconImage? { + func icon(for feed: Feed) -> IconImage? { if let cachedImage = cache[feed] { return cachedImage @@ -118,7 +118,7 @@ private extension FeedIconDownloader { static let specialCasesToSkip = ["macsparky.com", "xkcd.com", SpecialCase.rachelByTheBayHostName, SpecialCase.openRSSOrgHostName] - static func shouldSkipDownloadingFeedIcon(feed: WebFeed) -> Bool { + static func shouldSkipDownloadingFeedIcon(feed: Feed) -> Bool { shouldSkipDownloadingFeedIcon(feed.url) } @@ -126,7 +126,7 @@ private extension FeedIconDownloader { SpecialCase.urlStringContainSpecialCase(urlString, specialCasesToSkip) } - func icon(forHomePageURL homePageURL: String, feed: WebFeed, _ resultBlock: @escaping (RSImage?, String?) -> Void) { + func icon(forHomePageURL homePageURL: String, feed: Feed, _ resultBlock: @escaping (RSImage?, String?) -> Void) { if Self.shouldSkipDownloadingFeedIcon(homePageURL) { resultBlock(nil, nil) return @@ -154,7 +154,7 @@ private extension FeedIconDownloader { resultBlock(nil, nil) } - func icon(forURL url: String, feed: WebFeed, _ imageResultBlock: @escaping (RSImage?) -> Void) { + func icon(forURL url: String, feed: Feed, _ imageResultBlock: @escaping (RSImage?) -> Void) { waitingForFeedURLs[url] = feed guard let imageData = imageDownloader.image(for: url) else { @@ -164,10 +164,10 @@ private extension FeedIconDownloader { RSImage.scaledForIcon(imageData, imageResultBlock: imageResultBlock) } - func postFeedIconDidBecomeAvailableNotification(_ feed: WebFeed) { + func postFeedIconDidBecomeAvailableNotification(_ feed: Feed) { DispatchQueue.main.async { - let userInfo: [AnyHashable: Any] = [UserInfoKey.webFeed: feed] + let userInfo: [AnyHashable: Any] = [UserInfoKey.feed: feed] NotificationCenter.default.post(name: .feedIconDidBecomeAvailable, object: self, userInfo: userInfo) } } diff --git a/Shared/ShareExtension/ExtensionFeedAddRequestFile.swift b/Shared/ShareExtension/ExtensionFeedAddRequestFile.swift index c8cff0220..bf64416b6 100644 --- a/Shared/ShareExtension/ExtensionFeedAddRequestFile.swift +++ b/Shared/ShareExtension/ExtensionFeedAddRequestFile.swift @@ -153,6 +153,6 @@ private extension ExtensionFeedAddRequestFile { guard let container = destinationContainer else { return } - account.createWebFeed(url: request.feedURL.absoluteString, name: request.name, container: container, validateFeed: true) { _ in } + account.createFeed(url: request.feedURL.absoluteString, name: request.name, container: container, validateFeed: true) { _ in } } } diff --git a/Shared/ShareExtension/ShareDefaultContainer.swift b/Shared/ShareExtension/ShareDefaultContainer.swift index ecacd8d1e..5cc5ef24e 100644 --- a/Shared/ShareExtension/ShareDefaultContainer.swift +++ b/Shared/ShareExtension/ShareDefaultContainer.swift @@ -12,8 +12,8 @@ struct ShareDefaultContainer { static func defaultContainer(containers: ExtensionContainers) -> ExtensionContainer? { - if let accountID = AppDefaults.shared.addWebFeedAccountID, let account = containers.accounts.first(where: { $0.accountID == accountID }) { - if let folderName = AppDefaults.shared.addWebFeedFolderName, let folder = account.folders.first(where: { $0.name == folderName }) { + if let accountID = AppDefaults.shared.addFeedAccountID, let account = containers.accounts.first(where: { $0.accountID == accountID }) { + if let folderName = AppDefaults.shared.addFeedFolderName, let folder = account.folders.first(where: { $0.name == folderName }) { return folder } else { return substituteContainerIfNeeded(account: account) @@ -27,11 +27,11 @@ struct ShareDefaultContainer { } static func saveDefaultContainer(_ container: ExtensionContainer) { - AppDefaults.shared.addWebFeedAccountID = container.accountID + AppDefaults.shared.addFeedAccountID = container.accountID if let folder = container as? ExtensionFolder { - AppDefaults.shared.addWebFeedFolderName = folder.name + AppDefaults.shared.addFeedFolderName = folder.name } else { - AppDefaults.shared.addWebFeedFolderName = nil + AppDefaults.shared.addFeedFolderName = nil } } diff --git a/Shared/Timeline/ArticleSorter.swift b/Shared/Timeline/ArticleSorter.swift index 50e91d8a8..c7ba1a748 100644 --- a/Shared/Timeline/ArticleSorter.swift +++ b/Shared/Timeline/ArticleSorter.swift @@ -13,7 +13,7 @@ protocol SortableArticle { var sortableName: String { get } var sortableDate: Date { get } var sortableArticleID: String { get } - var sortableWebFeedID: String { get } + var sortableFeedID: String { get } } struct ArticleSorter { @@ -34,7 +34,7 @@ struct ArticleSorter { sortByDateDirection: ComparisonResult) -> [T] { // Group articles by "feed-feedID" - feed ID is used to differentiate between // two feeds that have the same name - let groupedArticles = Dictionary(grouping: articles) { "\($0.sortableName.lowercased())-\($0.sortableWebFeedID)" } + let groupedArticles = Dictionary(grouping: articles) { "\($0.sortableName.lowercased())-\($0.sortableFeedID)" } return groupedArticles .sorted { $0.key < $1.key } .flatMap { (tuple) -> [T] in diff --git a/Shared/Tree/WebFeedTreeControllerDelegate.swift b/Shared/Tree/SidebarTreeControllerDelegate.swift similarity index 87% rename from Shared/Tree/WebFeedTreeControllerDelegate.swift rename to Shared/Tree/SidebarTreeControllerDelegate.swift index 31f7a59ae..e6369c32e 100644 --- a/Shared/Tree/WebFeedTreeControllerDelegate.swift +++ b/Shared/Tree/SidebarTreeControllerDelegate.swift @@ -11,7 +11,7 @@ import RSTree import Articles import Account -final class WebFeedTreeControllerDelegate: TreeControllerDelegate { +final class SidebarTreeControllerDelegate: TreeControllerDelegate { private var filterExceptions = Set() var isReadFiltered = false @@ -39,7 +39,7 @@ final class WebFeedTreeControllerDelegate: TreeControllerDelegate { } } -private extension WebFeedTreeControllerDelegate { +private extension SidebarTreeControllerDelegate { func childNodesForRootNode(_ rootNode: Node) -> [Node]? { var topLevelNodes = [Node]() @@ -66,9 +66,9 @@ private extension WebFeedTreeControllerDelegate { var children = [AnyObject]() - for webFeed in container.topLevelWebFeeds { - if let sidebarItemID = webFeed.sidebarItemID, !(!filterExceptions.contains(sidebarItemID) && isReadFiltered && webFeed.unreadCount == 0) { - children.append(webFeed) + for feed in container.topLevelFeeds { + if let sidebarItemID = feed.sidebarItemID, !(!filterExceptions.contains(sidebarItemID) && isReadFiltered && feed.unreadCount == 0) { + children.append(feed) } } @@ -100,8 +100,8 @@ private extension WebFeedTreeControllerDelegate { } func createNode(representedObject: Any, parent: Node) -> Node? { - if let webFeed = representedObject as? WebFeed { - return createNode(webFeed: webFeed, parent: parent) + if let feed = representedObject as? Feed { + return createNode(feed: feed, parent: parent) } if let folder = representedObject as? Folder { @@ -115,8 +115,8 @@ private extension WebFeedTreeControllerDelegate { return nil } - func createNode(webFeed: WebFeed, parent: Node) -> Node { - return parent.createChildNode(webFeed) + func createNode(feed: Feed, parent: Node) -> Node { + return parent.createChildNode(feed) } func createNode(folder: Folder, parent: Node) -> Node { diff --git a/Shared/UserInfoKey.swift b/Shared/UserInfoKey.swift index e9aaa21fc..ae44ca44e 100644 --- a/Shared/UserInfoKey.swift +++ b/Shared/UserInfoKey.swift @@ -10,7 +10,7 @@ import Foundation struct UserInfoKey { - static let webFeed = "webFeed" + static let feed = "feed" static let url = "url" static let articlePath = "articlePath" static let feedIdentifier = "feedIdentifier" diff --git a/Shared/UserNotifications/UserNotificationManager.swift b/Shared/UserNotifications/UserNotificationManager.swift index 35523f595..97cb2b4b1 100644 --- a/Shared/UserNotifications/UserNotificationManager.swift +++ b/Shared/UserNotifications/UserNotificationManager.swift @@ -26,8 +26,8 @@ final class UserNotificationManager: NSObject { } for article in articles { - if !article.status.read, let webFeed = article.webFeed, webFeed.isNotifyAboutNewArticles ?? false { - sendNotification(webFeed: webFeed, article: article) + if !article.status.read, let feed = article.feed, feed.isNotifyAboutNewArticles ?? false { + sendNotification(feed: feed, article: article) } } } @@ -53,19 +53,19 @@ final class UserNotificationManager: NSObject { private extension UserNotificationManager { - func sendNotification(webFeed: WebFeed, article: Article) { + func sendNotification(feed: Feed, article: Article) { let content = UNMutableNotificationContent() - content.title = webFeed.nameForDisplay + content.title = feed.nameForDisplay if !ArticleStringFormatter.truncatedTitle(article).isEmpty { content.subtitle = ArticleStringFormatter.truncatedTitle(article) } content.body = ArticleStringFormatter.truncatedSummary(article) - content.threadIdentifier = webFeed.webFeedID + content.threadIdentifier = feed.feedID content.sound = UNNotificationSound.default content.userInfo = [UserInfoKey.articlePath: article.pathUserInfo] content.categoryIdentifier = "NEW_ARTICLE_NOTIFICATION_CATEGORY" - if let attachment = thumbnailAttachment(for: article, webFeed: webFeed) { + if let attachment = thumbnailAttachment(for: article, feed: feed) { content.attachments.append(attachment) } @@ -76,12 +76,12 @@ private extension UserNotificationManager { /// Determine if there is an available icon for the article. This will then move it to the caches directory and make it avialble for the notification. /// - Parameters: /// - article: `Article` - /// - webFeed: `WebFeed` + /// - feed: `Feed` /// - Returns: A `UNNotifcationAttachment` if an icon is available. Otherwise nil. /// - Warning: In certain scenarios, this will return the `faviconTemplateImage`. - func thumbnailAttachment(for article: Article, webFeed: WebFeed) -> UNNotificationAttachment? { - if let imageURL = article.iconImageUrl(webFeed: webFeed) { - let thumbnail = try? UNNotificationAttachment(identifier: webFeed.webFeedID, url: imageURL, options: nil) + func thumbnailAttachment(for article: Article, feed: Feed) -> UNNotificationAttachment? { + if let imageURL = article.iconImageUrl(feed: feed) { + let thumbnail = try? UNNotificationAttachment(identifier: feed.feedID, url: imageURL, options: nil) return thumbnail } return nil diff --git a/Tests/NetNewsWireTests/ArticleSorterTests.swift b/Tests/NetNewsWireTests/ArticleSorterTests.swift index a57f000ab..8e6989092 100644 --- a/Tests/NetNewsWireTests/ArticleSorterTests.swift +++ b/Tests/NetNewsWireTests/ArticleSorterTests.swift @@ -19,10 +19,10 @@ final class ArticleSorterTests: XCTestCase { func testSortByDateAscending() { let now = Date() - let article1 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-60.0), sortableArticleID: "1", sortableWebFeedID: "4") - let article2 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(60.0), sortableArticleID: "2", sortableWebFeedID: "6") - let article3 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(120.0), sortableArticleID: "3", sortableWebFeedID: "6") - let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-120.0), sortableArticleID: "4", sortableWebFeedID: "5") + let article1 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-60.0), sortableArticleID: "1", sortableFeedID: "4") + let article2 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(60.0), sortableArticleID: "2", sortableFeedID: "6") + let article3 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(120.0), sortableArticleID: "3", sortableFeedID: "6") + let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-120.0), sortableArticleID: "4", sortableFeedID: "5") let articles = [article1, article2, article3, article4] let sortedArticles = ArticleSorter.sortedByDate(articles: articles, @@ -40,11 +40,11 @@ final class ArticleSorterTests: XCTestCase { let now = Date() // Articles with the same date should end up being sorted by their article ID - let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "1", sortableWebFeedID: "1") - let article2 = TestArticle(sortableName: "Matt's Feed", sortableDate: now, sortableArticleID: "2", sortableWebFeedID: "2") - let article3 = TestArticle(sortableName: "Sally's Feed", sortableDate: now, sortableArticleID: "3", sortableWebFeedID: "3") - let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: Date(timeInterval: -60.0, since: now), sortableArticleID: "4", sortableWebFeedID: "4") - let article5 = TestArticle(sortableName: "Paul's Feed", sortableDate: Date(timeInterval: -120.0, since: now), sortableArticleID: "5", sortableWebFeedID: "5") + let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "1") + let article2 = TestArticle(sortableName: "Matt's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "2") + let article3 = TestArticle(sortableName: "Sally's Feed", sortableDate: now, sortableArticleID: "3", sortableFeedID: "3") + let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: Date(timeInterval: -60.0, since: now), sortableArticleID: "4", sortableFeedID: "4") + let article5 = TestArticle(sortableName: "Paul's Feed", sortableDate: Date(timeInterval: -120.0, since: now), sortableArticleID: "5", sortableFeedID: "5") let articles = [article1, article2, article3, article4, article5] let sortedArticles = ArticleSorter.sortedByDate(articles: articles, @@ -62,15 +62,15 @@ final class ArticleSorterTests: XCTestCase { func testSortByDateAscendingWithGroupByFeed() { let now = Date() - let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: Date(timeInterval: -100.0, since: now), sortableArticleID: "1", sortableWebFeedID: "1") - let article2 = TestArticle(sortableName: "Jenny's Feed", sortableDate: now, sortableArticleID: "1", sortableWebFeedID: "2") - let article3 = TestArticle(sortableName: "Jenny's Feed", sortableDate: Date(timeInterval: -10.0, since: now), sortableArticleID: "2", sortableWebFeedID: "2") - let article4 = TestArticle(sortableName: "Gordy's Blog", sortableDate: Date(timeInterval: -1000.0, since: now), sortableArticleID: "1", sortableWebFeedID: "3") - let article5 = TestArticle(sortableName: "Gordy's Blog", sortableDate: Date(timeInterval: -10.0, since: now), sortableArticleID: "2", sortableWebFeedID: "3") - let article6 = TestArticle(sortableName: "Jenny's Feed", sortableDate: Date(timeInterval: 10.0, since: now), sortableArticleID: "3", sortableWebFeedID: "2") - let article7 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "2", sortableWebFeedID: "1") - let article8 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "1", sortableWebFeedID: "0") - let article9 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "2", sortableWebFeedID: "0") + let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: Date(timeInterval: -100.0, since: now), sortableArticleID: "1", sortableFeedID: "1") + let article2 = TestArticle(sortableName: "Jenny's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "2") + let article3 = TestArticle(sortableName: "Jenny's Feed", sortableDate: Date(timeInterval: -10.0, since: now), sortableArticleID: "2", sortableFeedID: "2") + let article4 = TestArticle(sortableName: "Gordy's Blog", sortableDate: Date(timeInterval: -1000.0, since: now), sortableArticleID: "1", sortableFeedID: "3") + let article5 = TestArticle(sortableName: "Gordy's Blog", sortableDate: Date(timeInterval: -10.0, since: now), sortableArticleID: "2", sortableFeedID: "3") + let article6 = TestArticle(sortableName: "Jenny's Feed", sortableDate: Date(timeInterval: 10.0, since: now), sortableArticleID: "3", sortableFeedID: "2") + let article7 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "1") + let article8 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "0") + let article9 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "0") let articles = [article1, article2, article3, article4, article5, article6, article7, article8, article9] let sortedArticles = ArticleSorter.sortedByDate(articles: articles, sortDirection: .orderedAscending, groupByFeed: true) @@ -97,10 +97,10 @@ final class ArticleSorterTests: XCTestCase { func testSortByDateDescending() { let now = Date() - let article1 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-60.0), sortableArticleID: "1", sortableWebFeedID: "4") - let article2 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(60.0), sortableArticleID: "2", sortableWebFeedID: "6") - let article3 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(120.0), sortableArticleID: "3", sortableWebFeedID: "6") - let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-120.0), sortableArticleID: "4", sortableWebFeedID: "5") + let article1 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-60.0), sortableArticleID: "1", sortableFeedID: "4") + let article2 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(60.0), sortableArticleID: "2", sortableFeedID: "6") + let article3 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(120.0), sortableArticleID: "3", sortableFeedID: "6") + let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-120.0), sortableArticleID: "4", sortableFeedID: "5") let articles = [article1, article2, article3, article4] let sortedArticles = ArticleSorter.sortedByDate(articles: articles, @@ -118,11 +118,11 @@ final class ArticleSorterTests: XCTestCase { let now = Date() // Articles with the same date should end up being sorted by their article ID - let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "1", sortableWebFeedID: "1") - let article2 = TestArticle(sortableName: "Matt's Feed", sortableDate: now, sortableArticleID: "2", sortableWebFeedID: "2") - let article3 = TestArticle(sortableName: "Sally's Feed", sortableDate: now, sortableArticleID: "3", sortableWebFeedID: "3") - let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: Date(timeInterval: -60.0, since: now), sortableArticleID: "4", sortableWebFeedID: "4") - let article5 = TestArticle(sortableName: "Paul's Feed", sortableDate: Date(timeInterval: -120.0, since: now), sortableArticleID: "5", sortableWebFeedID: "5") + let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "1") + let article2 = TestArticle(sortableName: "Matt's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "2") + let article3 = TestArticle(sortableName: "Sally's Feed", sortableDate: now, sortableArticleID: "3", sortableFeedID: "3") + let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: Date(timeInterval: -60.0, since: now), sortableArticleID: "4", sortableFeedID: "4") + let article5 = TestArticle(sortableName: "Paul's Feed", sortableDate: Date(timeInterval: -120.0, since: now), sortableArticleID: "5", sortableFeedID: "5") let articles = [article1, article2, article3, article4, article5] let sortedArticles = ArticleSorter.sortedByDate(articles: articles, @@ -140,15 +140,15 @@ final class ArticleSorterTests: XCTestCase { func testSortByDateDescendingWithGroupByFeed() { let now = Date() - let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: Date(timeInterval: -100.0, since: now), sortableArticleID: "1", sortableWebFeedID: "1") - let article2 = TestArticle(sortableName: "Jenny's Feed", sortableDate: now, sortableArticleID: "1", sortableWebFeedID: "2") - let article3 = TestArticle(sortableName: "Jenny's Feed", sortableDate: Date(timeInterval: -10.0, since: now), sortableArticleID: "2", sortableWebFeedID: "2") - let article4 = TestArticle(sortableName: "Gordy's Blog", sortableDate: Date(timeInterval: -1000.0, since: now), sortableArticleID: "1", sortableWebFeedID: "3") - let article5 = TestArticle(sortableName: "Gordy's Blog", sortableDate: Date(timeInterval: -10.0, since: now), sortableArticleID: "2", sortableWebFeedID: "3") - let article6 = TestArticle(sortableName: "Jenny's Feed", sortableDate: Date(timeInterval: 10.0, since: now), sortableArticleID: "3", sortableWebFeedID: "2") - let article7 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "2", sortableWebFeedID: "1") - let article8 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "1", sortableWebFeedID: "0") - let article9 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "2", sortableWebFeedID: "0") + let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: Date(timeInterval: -100.0, since: now), sortableArticleID: "1", sortableFeedID: "1") + let article2 = TestArticle(sortableName: "Jenny's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "2") + let article3 = TestArticle(sortableName: "Jenny's Feed", sortableDate: Date(timeInterval: -10.0, since: now), sortableArticleID: "2", sortableFeedID: "2") + let article4 = TestArticle(sortableName: "Gordy's Blog", sortableDate: Date(timeInterval: -1000.0, since: now), sortableArticleID: "1", sortableFeedID: "3") + let article5 = TestArticle(sortableName: "Gordy's Blog", sortableDate: Date(timeInterval: -10.0, since: now), sortableArticleID: "2", sortableFeedID: "3") + let article6 = TestArticle(sortableName: "Jenny's Feed", sortableDate: Date(timeInterval: 10.0, since: now), sortableArticleID: "3", sortableFeedID: "2") + let article7 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "1") + let article8 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "0") + let article9 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "0") let articles = [article1, article2, article3, article4, article5, article6, article7, article8, article9] let sortedArticles = ArticleSorter.sortedByDate(articles: articles, sortDirection: .orderedDescending, groupByFeed: true) @@ -175,11 +175,11 @@ final class ArticleSorterTests: XCTestCase { func testGroupByFeedWithCaseInsensitiveFeedNames() { let now = Date() - let article1 = TestArticle(sortableName: "phil's feed", sortableDate: now, sortableArticleID: "1", sortableWebFeedID: "1") - let article2 = TestArticle(sortableName: "PhIl's FEed", sortableDate: now, sortableArticleID: "2", sortableWebFeedID: "1") - let article3 = TestArticle(sortableName: "APPLE's feed", sortableDate: now, sortableArticleID: "3", sortableWebFeedID: "2") - let article4 = TestArticle(sortableName: "PHIL'S FEED", sortableDate: now, sortableArticleID: "4", sortableWebFeedID: "1") - let article5 = TestArticle(sortableName: "apple's feed", sortableDate: now, sortableArticleID: "5", sortableWebFeedID: "2") + let article1 = TestArticle(sortableName: "phil's feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "1") + let article2 = TestArticle(sortableName: "PhIl's FEed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "1") + let article3 = TestArticle(sortableName: "APPLE's feed", sortableDate: now, sortableArticleID: "3", sortableFeedID: "2") + let article4 = TestArticle(sortableName: "PHIL'S FEED", sortableDate: now, sortableArticleID: "4", sortableFeedID: "1") + let article5 = TestArticle(sortableName: "apple's feed", sortableDate: now, sortableArticleID: "5", sortableFeedID: "2") let articles = [article1, article2, article3, article4, article5] let sortedArticles = ArticleSorter.sortedByDate(articles: articles, @@ -201,11 +201,11 @@ final class ArticleSorterTests: XCTestCase { let now = Date() // Articles with the same feed name should be sorted by feed ID - let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "1", sortableWebFeedID: "2") - let article2 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "2", sortableWebFeedID: "2") - let article3 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "3", sortableWebFeedID: "1") - let article4 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "4", sortableWebFeedID: "2") - let article5 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "5", sortableWebFeedID: "1") + let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "2") + let article2 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "2") + let article3 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "3", sortableFeedID: "1") + let article4 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "4", sortableFeedID: "2") + let article5 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "5", sortableFeedID: "1") let articles = [article1, article2, article3, article4, article5] let sortedArticles = ArticleSorter.sortedByDate(articles: articles, @@ -226,7 +226,7 @@ private struct TestArticle: SortableArticle, Equatable { let sortableName: String let sortableDate: Date let sortableArticleID: String - let sortableWebFeedID: String + let sortableFeedID: String } private extension Array where Element == TestArticle { diff --git a/Tests/NetNewsWireTests/ScriptingTests/scripts/testFeedExists.applescript b/Tests/NetNewsWireTests/ScriptingTests/scripts/testFeedExists.applescript index 8eafaad24..098c1ff61 100644 --- a/Tests/NetNewsWireTests/ScriptingTests/scripts/testFeedExists.applescript +++ b/Tests/NetNewsWireTests/ScriptingTests/scripts/testFeedExists.applescript @@ -1,7 +1,7 @@ -- this script just tests that no error was generated from the script try tell application "NetNewsWire" - exists webFeed 1 of account 1 + exists feed 1 of account 1 end tell on error message return {test_result:false, script_result:message} diff --git a/Tests/NetNewsWireTests/ScriptingTests/scripts/testNameAndUrlOfEveryFeed.applescript b/Tests/NetNewsWireTests/ScriptingTests/scripts/testNameAndUrlOfEveryFeed.applescript index 7e21f3991..86268914b 100644 --- a/Tests/NetNewsWireTests/ScriptingTests/scripts/testNameAndUrlOfEveryFeed.applescript +++ b/Tests/NetNewsWireTests/ScriptingTests/scripts/testNameAndUrlOfEveryFeed.applescript @@ -1,7 +1,7 @@ -- this script just tests that no error was generated from the script try tell application "NetNewsWire" - {name, url} of every webFeed of every account + {name, url} of every feed of every account end tell on error message return {test_result:false, script_result:message} diff --git a/Tests/NetNewsWireTests/ScriptingTests/scripts/testNameOfAuthors.applescript b/Tests/NetNewsWireTests/ScriptingTests/scripts/testNameOfAuthors.applescript index d88df5b9c..db15bab30 100644 --- a/Tests/NetNewsWireTests/ScriptingTests/scripts/testNameOfAuthors.applescript +++ b/Tests/NetNewsWireTests/ScriptingTests/scripts/testNameOfAuthors.applescript @@ -2,7 +2,7 @@ -- and that the returned list is greater than 0 try tell application "NetNewsWire" - set namesResult to name of every author of every webFeed of every account + set namesResult to name of every author of every feed of every account end tell set test_result to ((count items of namesResult) > 0) on error message diff --git a/Tests/NetNewsWireTests/SharingTests.swift b/Tests/NetNewsWireTests/SharingTests.swift index 886974961..371838462 100644 --- a/Tests/NetNewsWireTests/SharingTests.swift +++ b/Tests/NetNewsWireTests/SharingTests.swift @@ -42,7 +42,7 @@ final class SharingTests: XCTestCase { let articleId = randomId() return Article(accountID: randomId(), articleID: articleId, - webFeedID: randomId(), + feedID: randomId(), uniqueID: randomId(), title: title, contentHTML: nil, diff --git a/iOS/Add/Add.storyboard b/iOS/Add/Add.storyboard index e174f6048..1cab8a297 100644 --- a/iOS/Add/Add.storyboard +++ b/iOS/Add/Add.storyboard @@ -1,16 +1,16 @@ - + - + - + - + @@ -125,7 +125,7 @@ - + @@ -141,7 +141,7 @@ - + @@ -237,7 +237,7 @@ - + diff --git a/iOS/Add/AddFeedViewController.swift b/iOS/Add/AddFeedViewController.swift index 2a7322849..bc4b65e42 100644 --- a/iOS/Add/AddFeedViewController.swift +++ b/iOS/Add/AddFeedViewController.swift @@ -52,7 +52,7 @@ final class AddFeedViewController: UITableViewController { nameTextField.text = initialFeedName nameTextField.delegate = self - if let defaultContainer = AddWebFeedDefaultContainer.defaultContainer { + if let defaultContainer = AddFeedDefaultContainer.defaultContainer { container = defaultContainer } else { addButton.isEnabled = false @@ -92,7 +92,7 @@ final class AddFeedViewController: UITableViewController { account = containerAccount } - if account!.hasWebFeed(withURL: url.absoluteString) { + if account!.hasFeed(withURL: url.absoluteString) { presentError(AccountError.createErrorAlreadySubscribed) return } @@ -106,14 +106,14 @@ final class AddFeedViewController: UITableViewController { BatchUpdate.shared.start() - account!.createWebFeed(url: url.absoluteString, name: feedName, container: container, validateFeed: true) { result in + account!.createFeed(url: url.absoluteString, name: feedName, container: container, validateFeed: true) { result in BatchUpdate.shared.end() switch result { case .success(let feed): self.dismiss(animated: true) - NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.webFeed: feed]) + NotificationCenter.default.post(name: .UserDidAddFeed, object: self, userInfo: [UserInfoKey.feed: feed]) case .failure(let error): self.addButton.isEnabled = true self.activityIndicator.stopAnimating() @@ -141,7 +141,7 @@ final class AddFeedViewController: UITableViewController { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.row == 2 { - let navController = UIStoryboard.add.instantiateViewController(withIdentifier: "AddWebFeedFolderNavViewController") as! UINavigationController + let navController = UIStoryboard.add.instantiateViewController(withIdentifier: "AddFeedFolderNavViewController") as! UINavigationController navController.modalPresentationStyle = .currentContext let folderViewController = navController.topViewController as! AddFeedFolderViewController folderViewController.delegate = self @@ -152,13 +152,13 @@ final class AddFeedViewController: UITableViewController { } -// MARK: AddWebFeedFolderViewControllerDelegate +// MARK: AddFeedFolderViewControllerDelegate extension AddFeedViewController: AddFeedFolderViewControllerDelegate { func didSelect(container: Container) { self.container = container updateFolderLabel() - AddWebFeedDefaultContainer.saveDefaultContainer(container) + AddFeedDefaultContainer.saveDefaultContainer(container) } } diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index 878838128..7afbeebc0 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -56,8 +56,8 @@ final class AppDefaults { static let articleFullscreenEnabled = "articleFullscreenEnabled" static let confirmMarkAllAsRead = "confirmMarkAllAsRead" static let lastRefresh = "lastRefresh" - static let addWebFeedAccountID = "addWebFeedAccountID" - static let addWebFeedFolderName = "addWebFeedFolderName" + static let addFeedAccountID = "addFeedAccountID" + static let addFeedFolderName = "addFeedFolderName" static let addFolderAccountID = "addFolderAccountID" static let useSystemBrowser = "useSystemBrowser" static let currentThemeName = "currentThemeName" @@ -92,21 +92,21 @@ final class AppDefaults { } } - var addWebFeedAccountID: String? { + var addFeedAccountID: String? { get { - return AppDefaults.string(for: Key.addWebFeedAccountID) + return AppDefaults.string(for: Key.addFeedAccountID) } set { - AppDefaults.setString(for: Key.addWebFeedAccountID, newValue) + AppDefaults.setString(for: Key.addFeedAccountID, newValue) } } - var addWebFeedFolderName: String? { + var addFeedFolderName: String? { get { - return AppDefaults.string(for: Key.addWebFeedFolderName) + return AppDefaults.string(for: Key.addFeedFolderName) } set { - AppDefaults.setString(for: Key.addWebFeedFolderName, newValue) + AppDefaults.setString(for: Key.addFeedFolderName, newValue) } } diff --git a/iOS/Article/ContextMenuPreviewViewController.swift b/iOS/Article/ContextMenuPreviewViewController.swift index 345bfed2d..6752220f2 100644 --- a/iOS/Article/ContextMenuPreviewViewController.swift +++ b/iOS/Article/ContextMenuPreviewViewController.swift @@ -21,7 +21,7 @@ final class ContextMenuPreviewViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - blogNameLabel.text = article.webFeed?.nameForDisplay ?? "" + blogNameLabel.text = article.feed?.nameForDisplay ?? "" blogAuthorLabel.text = article.byline() articleTitleLabel.text = article.title ?? "" diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 92544b873..58fd92948 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -70,7 +70,7 @@ final class WebViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - NotificationCenter.default.addObserver(self, selector: #selector(webFeedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(avatarDidBecomeAvailable(_:)), name: .AvatarDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(currentArticleThemeDidChangeNotification(_:)), name: .CurrentArticleThemeDidChangeNotification, object: nil) @@ -84,7 +84,7 @@ final class WebViewController: UIViewController { // MARK: Notifications - @objc func webFeedIconDidBecomeAvailable(_ note: Notification) { + @objc func feedIconDidBecomeAvailable(_ note: Notification) { reloadArticleImage() } @@ -114,7 +114,7 @@ final class WebViewController: UIViewController { if article != self.article { self.article = article if updateView { - if article?.webFeed?.isArticleExtractorAlwaysOn ?? false { + if article?.feed?.isArticleExtractorAlwaysOn ?? false { startArticleExtractor() } windowScrollY = 0 @@ -451,8 +451,8 @@ extension WebViewController: WKScriptMessageHandler { case MessageName.imageWasClicked: imageWasClicked(body: message.body as? String) case MessageName.showFeedInspector: - if let webFeed = article?.webFeed { - coordinator.showFeedInspector(for: webFeed) + if let feed = article?.feed { + coordinator.showFeedInspector(for: feed) } default: return diff --git a/iOS/Inspector/WebFeedInspectorViewController.swift b/iOS/Inspector/FeedInspectorViewController.swift similarity index 82% rename from iOS/Inspector/WebFeedInspectorViewController.swift rename to iOS/Inspector/FeedInspectorViewController.swift index 7aa882df2..b51c2dc92 100644 --- a/iOS/Inspector/WebFeedInspectorViewController.swift +++ b/iOS/Inspector/FeedInspectorViewController.swift @@ -1,5 +1,5 @@ // -// WebFeedInspectorViewController.swift +// FeedInspectorViewController.swift // NetNewsWire-iOS // // Created by Maurice Parker on 11/6/19. @@ -11,11 +11,11 @@ import Account import SafariServices import UserNotifications -final class WebFeedInspectorViewController: UITableViewController { +final class FeedInspectorViewController: UITableViewController { static let preferredContentSizeForFormSheetDisplay = CGSize(width: 460.0, height: 500.0) - var webFeed: WebFeed! + var feed: Feed! @IBOutlet weak var nameTextField: UITextField! @IBOutlet weak var notifyAboutNewArticlesSwitch: UISwitch! @IBOutlet weak var alwaysShowReaderViewSwitch: UISwitch! @@ -24,13 +24,13 @@ final class WebFeedInspectorViewController: UITableViewController { private var headerView: InspectorIconHeaderView? private var iconImage: IconImage? { - return IconImageCache.shared.imageForFeed(webFeed) + return IconImageCache.shared.imageForFeed(feed) } private let homePageIndexPath = IndexPath(row: 0, section: 1) private var shouldHideHomePageSection: Bool { - return webFeed.homePageURL == nil + return feed.homePageURL == nil } private var userNotificationSettings: UNNotificationSettings? @@ -38,17 +38,17 @@ final class WebFeedInspectorViewController: UITableViewController { override func viewDidLoad() { tableView.register(InspectorIconHeaderView.self, forHeaderFooterViewReuseIdentifier: "SectionHeader") - navigationItem.title = webFeed.nameForDisplay - nameTextField.text = webFeed.nameForDisplay + navigationItem.title = feed.nameForDisplay + nameTextField.text = feed.nameForDisplay - notifyAboutNewArticlesSwitch.setOn(webFeed.isNotifyAboutNewArticles ?? false, animated: false) + notifyAboutNewArticlesSwitch.setOn(feed.isNotifyAboutNewArticles ?? false, animated: false) - alwaysShowReaderViewSwitch.setOn(webFeed.isArticleExtractorAlwaysOn ?? false, animated: false) + alwaysShowReaderViewSwitch.setOn(feed.isArticleExtractorAlwaysOn ?? false, animated: false) - homePageLabel.text = webFeed.homePageURL - feedURLLabel.text = webFeed.url + homePageLabel.text = feed.homePageURL + feedURLLabel.text = feed.url - NotificationCenter.default.addObserver(self, selector: #selector(webFeedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .feedIconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(updateNotificationSettings), name: UIApplication.willEnterForegroundNotification, object: nil) @@ -59,15 +59,15 @@ final class WebFeedInspectorViewController: UITableViewController { } override func viewDidDisappear(_ animated: Bool) { - if nameTextField.text != webFeed.nameForDisplay { + if nameTextField.text != feed.nameForDisplay { let nameText = nameTextField.text ?? "" - let newName = nameText.isEmpty ? (webFeed.name ?? NSLocalizedString("Untitled", comment: "Feed name")) : nameText - webFeed.rename(to: newName) { _ in } + let newName = nameText.isEmpty ? (feed.name ?? NSLocalizedString("Untitled", comment: "Feed name")) : nameText + feed.rename(to: newName) { _ in } } } // MARK: Notifications - @objc func webFeedIconDidBecomeAvailable(_ notification: Notification) { + @objc func feedIconDidBecomeAvailable(_ notification: Notification) { headerView?.iconView.iconImage = iconImage } @@ -80,13 +80,13 @@ final class WebFeedInspectorViewController: UITableViewController { notifyAboutNewArticlesSwitch.isOn = !notifyAboutNewArticlesSwitch.isOn present(notificationUpdateErrorAlert(), animated: true, completion: nil) } else if settings.authorizationStatus == .authorized { - webFeed.isNotifyAboutNewArticles = notifyAboutNewArticlesSwitch.isOn + feed.isNotifyAboutNewArticles = notifyAboutNewArticlesSwitch.isOn } else { UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .sound, .alert]) { (granted, error) in self.updateNotificationSettings() if granted { DispatchQueue.main.async { - self.webFeed.isNotifyAboutNewArticles = self.notifyAboutNewArticlesSwitch.isOn + self.feed.isNotifyAboutNewArticles = self.notifyAboutNewArticlesSwitch.isOn UIApplication.shared.registerForRemoteNotifications() } } else { @@ -99,7 +99,7 @@ final class WebFeedInspectorViewController: UITableViewController { } @IBAction func alwaysShowReaderViewChanged(_ sender: Any) { - webFeed.isArticleExtractorAlwaysOn = alwaysShowReaderViewSwitch.isOn + feed.isArticleExtractorAlwaysOn = alwaysShowReaderViewSwitch.isOn } @IBAction func done(_ sender: Any) { @@ -128,7 +128,7 @@ final class WebFeedInspectorViewController: UITableViewController { // MARK: Table View -extension WebFeedInspectorViewController { +extension FeedInspectorViewController { override func numberOfSections(in tableView: UITableView) -> Int { let numberOfSections = super.numberOfSections(in: tableView) @@ -150,7 +150,7 @@ extension WebFeedInspectorViewController { return cell } label.numberOfLines = 2 - label.text = webFeed.notificationDisplayName.capitalized + label.text = feed.notificationDisplayName.capitalized } return cell } @@ -171,7 +171,7 @@ extension WebFeedInspectorViewController { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if shift(indexPath) == homePageIndexPath, - let homePageUrlString = webFeed.homePageURL, + let homePageUrlString = feed.homePageURL, let homePageUrl = URL(string: homePageUrlString) { let safari = SFSafariViewController(url: homePageUrl) @@ -186,7 +186,7 @@ extension WebFeedInspectorViewController { // MARK: UITextFieldDelegate -extension WebFeedInspectorViewController: UITextFieldDelegate { +extension FeedInspectorViewController: UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() @@ -197,7 +197,7 @@ extension WebFeedInspectorViewController: UITextFieldDelegate { // MARK: UNUserNotificationCenter -extension WebFeedInspectorViewController { +extension FeedInspectorViewController { @objc func updateNotificationSettings() { diff --git a/iOS/Inspector/Inspector.storyboard b/iOS/Inspector/Inspector.storyboard index 650a45286..408e5ed77 100644 --- a/iOS/Inspector/Inspector.storyboard +++ b/iOS/Inspector/Inspector.storyboard @@ -1,8 +1,8 @@ - + - + @@ -16,7 +16,7 @@ - +