From e2aa15f08a9c5ef1ea237a59a03b80f1b128dee6 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 5 Feb 2023 18:07:30 -0800 Subject: [PATCH] Create and use anyLocalOriCloudAccountHasAtLeastOneTwitterFeed in AccountManager, so both iOS and Mac apps can use it. Also: simplify the Date comparison in presentTwitterDeprecationAlertIfRequired by using Dates instead of TimeInterval. --- Account/Sources/Account/AccountManager.swift | 20 +++++++++++++++++ iOS/MasterFeed/MasterFeedViewController.swift | 22 +++---------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Account/Sources/Account/AccountManager.swift b/Account/Sources/Account/AccountManager.swift index fdaf47ccc..7a8c7acd8 100644 --- a/Account/Sources/Account/AccountManager.swift +++ b/Account/Sources/Account/AccountManager.swift @@ -351,6 +351,26 @@ public final class AccountManager: UnreadCountProvider { return false } + public func anyLocalOriCloudAccountHasAtLeastOneTwitterFeed() -> Bool { + // We removed our Twitter code, and the ability to read feeds from Twitter, + // when Twitter announced the end of the free tier for the Twitter API. + // We are cheering on Twitter’s increasing irrelevancy. + + for account in accounts { + if account.type == .cloudKit || account.type == .onMyMac { + for webfeed in account.flattenedWebFeeds() { + if let components = URLComponents(string: webfeed.url), let host = components.host { + if host == "twitter.com" { // Allow, for instance, blog.twitter.com, which might have an actual RSS feed + return true + } + } + } + } + } + + return false + } + // MARK: - Fetching Articles // These fetch articles from active accounts and return a merged Set
. diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 668077319..b0d847e60 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -717,28 +717,13 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { private func presentTwitterDeprecationAlertIfRequired() { if AppDefaults.shared.twitterDeprecationAlertShown { return } - let expiryDate = Date(timeIntervalSince1970: 1691539200).timeIntervalSince1970 // August 9th 2023, 00:00 UTC - let currentDate = Date().timeIntervalSince1970 + let expiryDate = Date(timeIntervalSince1970: 1691539200) // August 9th 2023, 00:00 UTC + let currentDate = Date() if currentDate > expiryDate { return // If after August 9th, don't show } - var twitterIsActive: Bool = false - AccountManager.shared.accounts.forEach({ account in - if account.type == .cloudKit || account.type == .onMyMac { - account.flattenedWebFeeds().forEach({ webfeed in - guard let components = URLComponents(string: webfeed.url), - let host = components.host else { - return - } - if host == "twitter.com" { - twitterIsActive = true - return - } - }) - } - }) - if twitterIsActive { + if AccountManager.shared.anyLocalOriCloudAccountHasAtLeastOneTwitterFeed() { showTwitterDeprecationAlert() } AppDefaults.shared.twitterDeprecationAlertShown = true @@ -752,7 +737,6 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { alert.addAction(UIAlertAction(title: "OK", style: .cancel)) present(alert, animated: true) } - } // MARK: UIContextMenuInteractionDelegate