From d4092b21fdf333e237f6e201c69d2bc795a5cdf4 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 2 Jul 2023 15:09:12 -0700 Subject: [PATCH] Add Reddit API deprecation alert code. --- iOS/AppDefaults.swift | 12 +++- iOS/MasterFeed/MasterFeedViewController.swift | 61 ++++++++++++++----- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index b75833965..d10a7e3d0 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -60,6 +60,7 @@ final class AppDefaults: ObservableObject { static let useSystemBrowser = "useSystemBrowser" static let currentThemeName = "currentThemeName" static let twitterDeprecationAlertShown = "twitterDeprecationAlertShown" + static let redditDeprecationAlertShown = "redditDeprecationAlertShown" static let markArticlesAsReadOnScroll = "markArticlesAsReadOnScroll" } @@ -255,7 +256,16 @@ final class AppDefaults: ObservableObject { AppDefaults.setBool(for: Key.twitterDeprecationAlertShown, newValue) } } - + + var redditDeprecationAlertShown: Bool { + get { + return AppDefaults.bool(for: Key.redditDeprecationAlertShown) + } + set { + AppDefaults.setBool(for: Key.redditDeprecationAlertShown, newValue) + } + } + var markArticlesAsReadOnScroll: Bool { get { return AppDefaults.bool(for: Key.markArticlesAsReadOnScroll) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 51fbc5511..3d990af27 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -98,9 +98,14 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner, Ma super.viewDidAppear(animated) if (isBeingPresented || isMovingToParent) { - // Only show the Twitter alert the first time + // Only show the Twitter or Reddit alert the first time // the view is presented. - presentTwitterDeprecationAlertIfRequired() + if shouldShowTwitterDeprecationAlert() { + showTwitterDeprecationAlert() + } + else if shouldShowRedditDeprecationAlert() { + showRedditDeprecationAlert() + } } } @@ -662,30 +667,54 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner, Ma } } - private func presentTwitterDeprecationAlertIfRequired() { - if AppDefaults.shared.twitterDeprecationAlertShown { return } - + private func shouldShowTwitterDeprecationAlert() -> Bool { + if AppDefaults.shared.twitterDeprecationAlertShown { return false } + 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 + return false // If after August 9th, don't show } - - if AccountManager.shared.anyLocalOriCloudAccountHasAtLeastOneTwitterFeed() { - showTwitterDeprecationAlert() - } - AppDefaults.shared.twitterDeprecationAlertShown = true + + return AccountManager.shared.anyLocalOriCloudAccountHasAtLeastOneTwitterFeed() } - + private func showTwitterDeprecationAlert() { - let alert = UIAlertController(title: NSLocalizedString("alert.title.twitter-integration-removed", comment: "Twitter Integration Removed"), - message: NSLocalizedString("alert.message.twitter-integration-removed", comment: "Twitter deprecation message"), + assert(shouldShowTwitterDeprecationAlert()) + AppDefaults.shared.twitterDeprecationAlertShown = true + + 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)) present(alert, animated: true) } -} + + private func shouldShowRedditDeprecationAlert() -> Bool { + if AppDefaults.shared.redditDeprecationAlertShown { return false } + + let expiryDate = Date(timeIntervalSince1970: 1701331200) // Thu Nov 30 2023 00:00:00 GMT-0800 (Pacific Standard Time) + let currentDate = Date() + if currentDate > expiryDate { + return false + } + + return AccountManager.shared.anyLocalOriCloudAccountHasAtLeastOneRedditAPIFeed() + } + + private func showRedditDeprecationAlert() { + assert(shouldShowRedditDeprecationAlert()) + AppDefaults.shared.redditDeprecationAlertShown = true + + let alert = UIAlertController(title: NSLocalizedString("Reddit API Integration Removed", comment: "Reddit API Integration Removed"), + message: 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, you can add Reddit RSS feeds and those feeds will continue to update.", comment: "Reddit deprecation message"), + preferredStyle: .alert) + + alert.addAction(UIAlertAction(title: "OK", style: .cancel)) + present(alert, animated: true) + } +}} // MARK: UIContextMenuInteractionDelegate