From 071a226d54e616fdcb88592ceb9017e16c22021f Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Thu, 28 Sep 2023 12:27:59 -0400 Subject: [PATCH] Fix #8167: Show Brave News onboarding if language support is added later This is only supported for new users since a new preference is required to track language check failures --- App/iOS/Delegates/AppDelegate.swift | 17 +++++++++++++---- Sources/BraveNews/NewsPreferences.swift | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/App/iOS/Delegates/AppDelegate.swift b/App/iOS/Delegates/AppDelegate.swift index de892e79dda..1cf86960d53 100644 --- a/App/iOS/Delegates/AppDelegate.swift +++ b/App/iOS/Delegates/AppDelegate.swift @@ -92,11 +92,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate { Preferences.BraveNews.isShowingOptIn.value = true } - if !Preferences.BraveNews.languageChecked.value, - let languageCode = Locale.preferredLanguages.first?.prefix(2) { + // If the user's language was checked but not included in the News supported languages list check it again + // each launch since updates could add support for a new language. If a user previously opted in to News + // however then we shouldn't show the opt-in card again. + let shouldPerformLanguageCheck = !Preferences.BraveNews.languageChecked.value || + Preferences.BraveNews.languageWasUnavailableDuringCheck.value == true + let isNewsEnabledOrPreviouslyOptedIn = Preferences.BraveNews.isEnabled.value || + Preferences.BraveNews.userOptedIn.value + if shouldPerformLanguageCheck, !isNewsEnabledOrPreviouslyOptedIn, + let languageCode = Locale.preferredLanguages.first?.prefix(2) { Preferences.BraveNews.languageChecked.value = true - // Base opt-in visibility on whether or not the user's language is supported in BT - Preferences.BraveNews.isShowingOptIn.value = FeedDataSource.supportedLanguages.contains(String(languageCode)) || FeedDataSource.knownSupportedLocales.contains(Locale.current.identifier) + let languageShouldShowOptIn = FeedDataSource.supportedLanguages.contains(String(languageCode)) || + FeedDataSource.knownSupportedLocales.contains(Locale.current.identifier) + Preferences.BraveNews.languageWasUnavailableDuringCheck.value = !languageShouldShowOptIn + Preferences.BraveNews.isShowingOptIn.value = languageShouldShowOptIn } SystemUtils.onFirstRun() diff --git a/Sources/BraveNews/NewsPreferences.swift b/Sources/BraveNews/NewsPreferences.swift index 2e659241738..8c171c0994b 100644 --- a/Sources/BraveNews/NewsPreferences.swift +++ b/Sources/BraveNews/NewsPreferences.swift @@ -12,6 +12,7 @@ extension Preferences { public static let userOptedIn = Option(key: "brave-today.user-opted-in", default: false) public static let isEnabled = Option(key: "brave-today.enabled", default: true) public static let languageChecked = Option(key: "brave-today.language-checked", default: false) + public static let languageWasUnavailableDuringCheck = Option(key: "brave-today.language-unavailable-when-checked", default: nil) public static let debugEnvironment = Option(key: "brave-today.debug.environment", default: nil) /// A list of channels followed for a locale. ///