Skip to content

Commit

Permalink
Fix brave/brave-ios#8167: Show Brave News onboarding if language supp…
Browse files Browse the repository at this point in the history
…ort is added later (brave/brave-ios#8170)

This is only supported for new users since a new preference is required to track language check failures
  • Loading branch information
kylehickinson authored Sep 28, 2023
1 parent 0395845 commit a6c20d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions App/iOS/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions Sources/BraveNews/NewsPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extension Preferences {
public static let userOptedIn = Option<Bool>(key: "brave-today.user-opted-in", default: false)
public static let isEnabled = Option<Bool>(key: "brave-today.enabled", default: true)
public static let languageChecked = Option<Bool>(key: "brave-today.language-checked", default: false)
public static let languageWasUnavailableDuringCheck = Option<Bool?>(key: "brave-today.language-unavailable-when-checked", default: nil)
public static let debugEnvironment = Option<String?>(key: "brave-today.debug.environment", default: nil)
/// A list of channels followed for a locale.
///
Expand Down

0 comments on commit a6c20d3

Please sign in to comment.