From 4dd3d60c7896c83bfdf5fbf65f65b8e89770888a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 25 Jun 2023 15:01:53 -0700 Subject: [PATCH] Create and use API to determine if there are any feeds that require the Reddit API. --- Account/Sources/Account/AccountManager.swift | 30 +++++++++++++++++++- Mac/AppDelegate.swift | 4 +-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Account/Sources/Account/AccountManager.swift b/Account/Sources/Account/AccountManager.swift index 8fbd56250..55bd3aead 100644 --- a/Account/Sources/Account/AccountManager.swift +++ b/Account/Sources/Account/AccountManager.swift @@ -370,7 +370,35 @@ public final class AccountManager: UnreadCountProvider { return false } - + + public func anyLocalOriCloudAccountHasAtLeastOneRedditAPIFeed() -> Bool { + // We removed our Reddit code, and the ability to read feeds from Reddit, + // when Reddit announced the end of the free tier for the Reddit API. + // We are cheering on Reddit’s increasing irrelevancy. + + for account in accounts { + if account.type == .cloudKit || account.type == .onMyMac { + for webfeed in account.flattenedWebFeeds() { + if feedRequiresRedditAPI(webfeed) { + return true + } + } + } + } + + return false + } + + /// Return true if a feed is for reddit.com and the path doesn’t end with .rss. + /// + /// More info: [Pathogen-David's Guide to RSS and Reddit!](https://www.reddit.com/r/pathogendavid/comments/tv8m9/pathogendavids_guide_to_rss_and_reddit/) + private func feedRequiresRedditAPI(_ feed: WebFeed) -> Bool { + if let components = URLComponents(string: webfeed.url), let host = components.host { + return host.hasSuffix("reddit.com") && !path.hasSuffix(".rss") + } + return false + } + // MARK: - Fetching Articles // These fetch articles from active accounts and return a merged Set
. diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 6d9451e1f..f365d022b 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -995,7 +995,7 @@ internal extension AppDelegate { return false } - return ExtensionPointManager.shared.isRedditEnabled + return AccountManager.shared.anyLocalOriCloudAccountHasAtLeastOneRedditAPIFeed() } private func showRedditDeprecationAlert() { @@ -1006,7 +1006,7 @@ internal extension AppDelegate { let alert = NSAlert() alert.alertStyle = .warning alert.messageText = NSLocalizedString("Reddit API Integration Removed", comment: "Reddit API Integration Removed") - alert.informativeText = NSLocalizedString("Reddit has announced the end of free access to their API, effective July 1.\n\nThough Reddit does provide RSS feeds, we use the Reddit API to get more and better data. But, without free access to that API, we will stop using it on June 30, 2023.\n\nWe’ve left your Reddit feeds intact. If you have any starred items from those feeds, they will remain as long as you don’t delete those feeds.\n\nYou can still read whatever you have already downloaded.\n\nAlso, importantly — after you remove Reddit from your extensions in NetNewsWire, you can add Reddit RSS feeds and those feeds will continue to update.", comment: "Reddit deprecation message") + alert.informativeText = NSLocalizedString("Reddit has ended free access to their API.\n\nThough Reddit does provide RSS feeds, we used the Reddit API to get more and better data. But, without free access to that API, we have had to stop using it.\n\nWe’ve left your Reddit feeds intact. If you have any starred items from those feeds, they will remain as long as you don’t delete those feeds.\n\nYou can still read whatever you have already downloaded.\n\nAlso, importantly — Reddit still provides RSS feeds, and you can follow Reddit activity through RSS.", comment: "Reddit deprecation message") alert.addButton(withTitle: NSLocalizedString("OK", comment: "OK")) alert.buttons[0].keyEquivalent = "\r" alert.runModal()