From b35c4df28df3e883ea3bb1b100d6f2df086d3aa4 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 5 Feb 2023 08:46:16 +0800 Subject: [PATCH 1/5] Shows Twitter Deprecation Alert on iOS --- iOS/AppDefaults.swift | 10 ++++ iOS/MasterFeed/MasterFeedViewController.swift | 51 ++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index 04b0fbadc..38242b0b9 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -58,6 +58,7 @@ final class AppDefaults { static let addFolderAccountID = "addFolderAccountID" static let useSystemBrowser = "useSystemBrowser" static let currentThemeName = "currentThemeName" + static let twitterDeprecationAlertShown = "twitterDeprecationAlertShown" } let isDeveloperBuild: Bool = { @@ -232,6 +233,15 @@ final class AppDefaults { } } + var twitterDeprecationAlertShown: Bool { + get { + return AppDefaults.bool(for: Key.twitterDeprecationAlertShown) + } + set { + AppDefaults.setBool(for: Key.twitterDeprecationAlertShown, newValue) + } + } + static func registerDefaults() { let defaults: [String : Any] = [Key.userInterfaceColorPalette: UserInterfaceColorPalette.automatic.rawValue, Key.timelineGroupByFeed: false, diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index f1d9fab78..e1dc931df 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -73,6 +73,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(configureContextMenu(_:)), name: .ActiveExtensionPointsDidChange, object: nil) + refreshControl = UIRefreshControl() refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged) @@ -86,6 +87,16 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { super.viewWillAppear(animated) } + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + + if (isBeingPresented || isMovingToParent) { + // Only show the Twitter alert the first time + // the view is presented. + presentTwitterDeprecationAlertIfRequired() + } + } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) if traitCollection.preferredContentSizeCategory != previousTraitCollection?.preferredContentSizeCategory { @@ -690,7 +701,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { self.addNewItemButton.menu = contextMenu } } - + func focus() { becomeFirstResponder() } @@ -703,6 +714,44 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } } + private func presentTwitterDeprecationAlertIfRequired() { + if AppDefaults.shared.twitterDeprecationAlertShown { return } + + let expiryDate = Date(timeIntervalSince1970: 1691510400).timeIntervalSince1970 // August 9th 2023 + let currentDate = Date().timeIntervalSince1970 + if currentDate > expiryDate { + return // If after August 9th, don't show + } + + var twitterIsActive: Bool = false + AccountManager.shared.accounts.forEach({ account in + account.flattenedWebFeeds().forEach({ webfeed in + guard let components = URLComponents(string: webfeed.url), + let host = components.host else { + return + } + print(host) + if host == "twitter.com" { + twitterIsActive = true + return + } + }) + }) + if twitterIsActive { + showTwitterDeprecationAlert() + } + AppDefaults.shared.twitterDeprecationAlertShown = true + } + + private func showTwitterDeprecationAlert() { + let alert = UIAlertController(title: "Twitter Integration Removed", + message: "On February 1, 2023, Twitter announced the end of free access to the Twitter API, effective February 9.\n\nSince Twitter does not provide RSS feeds, we’ve had to use the Twitter API. Without free access to that API, we can’t read feeds from Twitter.\n\nWe’ve left your Twitter 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. However, those feeds will no longer update.", + preferredStyle: .alert) + + alert.addAction(UIAlertAction(title: "OK", style: .cancel)) + present(alert, animated: true) + } + } // MARK: UIContextMenuInteractionDelegate From ee00339b4ced9fa1d9c527249d6ca922805ce382 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 5 Feb 2023 08:55:23 +0800 Subject: [PATCH 2/5] Removes print statement --- iOS/MasterFeed/MasterFeedViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index e1dc931df..74b4b953f 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -730,7 +730,6 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { let host = components.host else { return } - print(host) if host == "twitter.com" { twitterIsActive = true return From 757c680f4bb208aab5d3ba7c179b46ba4a3eac56 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 5 Feb 2023 09:04:23 +0800 Subject: [PATCH 3/5] Adjusted expiry date --- iOS/MasterFeed/MasterFeedViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 74b4b953f..38735c610 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -717,7 +717,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { private func presentTwitterDeprecationAlertIfRequired() { if AppDefaults.shared.twitterDeprecationAlertShown { return } - let expiryDate = Date(timeIntervalSince1970: 1691510400).timeIntervalSince1970 // August 9th 2023 + let expiryDate = Date(timeIntervalSince1970: 1691539200).timeIntervalSince1970 // August 9th 2023, 00:00 UTC let currentDate = Date().timeIntervalSince1970 if currentDate > expiryDate { return // If after August 9th, don't show From b2a2c5f5b9833e7a0ec8d095c048ffdc21fd344b Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 5 Feb 2023 09:45:34 +0800 Subject: [PATCH 4/5] Changes strings to NSLocalizedStrings --- iOS/MasterFeed/MasterFeedViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 38735c610..e0ab91b66 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -743,8 +743,8 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } private func showTwitterDeprecationAlert() { - let alert = UIAlertController(title: "Twitter Integration Removed", - message: "On February 1, 2023, Twitter announced the end of free access to the Twitter API, effective February 9.\n\nSince Twitter does not provide RSS feeds, we’ve had to use the Twitter API. Without free access to that API, we can’t read feeds from Twitter.\n\nWe’ve left your Twitter 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. However, those feeds will no longer update.", + let alert = UIAlertController(title: NSLocalizedString("Twitter Integration Removed", comment: "Twitter Integration Removed"), + message: NSLocalizedString("On February 1, 2023, Twitter announced the end of free access to the Twitter API, effective February 9.\n\nSince Twitter does not provide RSS feeds, we’ve had to use the Twitter API. Without free access to that API, we can’t read feeds from Twitter.\n\nWe’ve left your Twitter 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. However, those feeds will no longer update.", comment: "Twitter deprecation message"), preferredStyle: .alert) alert.addAction(UIAlertAction(title: "OK", style: .cancel)) From d5c039b80ff543858e6198f171c637cd15c1021a Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sun, 5 Feb 2023 21:29:19 +0800 Subject: [PATCH 5/5] Add account type check for Twitter deprecation --- iOS/MasterFeed/MasterFeedViewController.swift | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index e0ab91b66..668077319 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -725,16 +725,18 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { var twitterIsActive: Bool = false AccountManager.shared.accounts.forEach({ account in - 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 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 { showTwitterDeprecationAlert()