Skip to content

Commit

Permalink
Fix unwanted removal of content blockers upon launch (brave/brave-ios…
Browse files Browse the repository at this point in the history
…#8222)

* Fix unwanted removal of content blockers upon launch

* Use mutable reduce

* Change reduce to a map
  • Loading branch information
cuba authored Oct 11, 2023
1 parent 02a6cce commit 03a764b
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions Sources/Brave/Frontend/Browser/Helpers/LaunchHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@ public actor LaunchHelper {
/// Get all possible types of blocklist types available in this app, this includes actual and potential types
/// This is used to delete old filter lists so that we clean up old stuff
@MainActor private func getAllValidBlocklistTypes() -> Set<ContentBlockerManager.BlocklistType> {
return FilterListStorage.shared.filterLists
return FilterListStorage.shared
// All filter lists blocklist types
.reduce(Set<ContentBlockerManager.BlocklistType>()) { partialResult, filterList in
return partialResult.union([
.filterList(componentId: filterList.entry.componentId, isAlwaysAggressive: filterList.isAlwaysAggressive)
])
}
.validBlocklistTypes
// All generic types
.union(
ContentBlockerManager.GenericBlocklistType.allCases.map { .generic($0) }
Expand All @@ -127,6 +123,29 @@ public actor LaunchHelper {
}
}

private extension FilterListStorage {
/// Return all the blocklist types that are valid for filter lists.
var validBlocklistTypes: Set<ContentBlockerManager.BlocklistType> {
if filterLists.isEmpty {
// If we don't have filter lists yet loaded, use the settings
return Set(allFilterListSettings.compactMap { setting in
guard let componentId = setting.componentId else { return nil }
return .filterList(
componentId: componentId,
isAlwaysAggressive: setting.isAlwaysAggressive
)
})
} else {
// If we do have filter lists yet loaded, use them as they are always the most up to date and accurate
return Set(filterLists.map { filterList in
return .filterList(
componentId: filterList.entry.componentId,
isAlwaysAggressive: filterList.isAlwaysAggressive
)
})
}
}
}
private extension ShieldLevel {
/// Return a list of first launch content blocker modes that MUST be precompiled during launch
var firstLaunchBlockingModes: Set<ContentBlockerManager.BlockingMode> {
Expand Down

0 comments on commit 03a764b

Please sign in to comment.