diff --git a/DuckDuckGo/DBP/DataBrokerProtectionFeatureDisabler.swift b/DuckDuckGo/DBP/DataBrokerProtectionFeatureDisabler.swift index e0df3b67d7..54f99bad09 100644 --- a/DuckDuckGo/DBP/DataBrokerProtectionFeatureDisabler.swift +++ b/DuckDuckGo/DBP/DataBrokerProtectionFeatureDisabler.swift @@ -19,6 +19,10 @@ import Foundation import DataBrokerProtection +public extension Notification.Name { + static let dbpWasDisabled = Notification.Name("com.duckduckgo.DBP.DBPWasDisabled") +} + protocol DataBrokerProtectionFeatureDisabling { func disableAndDelete() } @@ -40,6 +44,8 @@ struct DataBrokerProtectionFeatureDisabler: DataBrokerProtectionFeatureDisabling scheduler.disableLoginItem() dataManager.removeAllData() + + NotificationCenter.default.post(name: .dbpWasDisabled, object: nil) } } } diff --git a/DuckDuckGo/DBP/DataBrokerProtectionSubscriptionEventHandler.swift b/DuckDuckGo/DBP/DataBrokerProtectionSubscriptionEventHandler.swift index 783c900d12..95a3f3405e 100644 --- a/DuckDuckGo/DBP/DataBrokerProtectionSubscriptionEventHandler.swift +++ b/DuckDuckGo/DBP/DataBrokerProtectionSubscriptionEventHandler.swift @@ -25,11 +25,14 @@ final class DataBrokerProtectionSubscriptionEventHandler { private let accountManager: Account.AccountManaging private let authRepository: AuthenticationRepository + private let featureDisabler: DataBrokerProtectionFeatureDisabling init(accountManager: Account.AccountManaging = Account.AccountManager(), - authRepository: AuthenticationRepository = KeychainAuthenticationData()) { + authRepository: AuthenticationRepository = KeychainAuthenticationData(), + featureDisabler: DataBrokerProtectionFeatureDisabling = DataBrokerProtectionFeatureDisabler()) { self.accountManager = accountManager self.authRepository = authRepository + self.featureDisabler = featureDisabler } func registerForSubscriptionAccountManagerEvents() { @@ -48,7 +51,7 @@ final class DataBrokerProtectionSubscriptionEventHandler { } @objc private func handleAccountDidSignOut() { - // Going to be defined here: https://app.asana.com/0/1204006570077678/1206206961074916/f + featureDisabler.disableAndDelete() } } diff --git a/DuckDuckGo/Tab/View/BrowserTabViewController.swift b/DuckDuckGo/Tab/View/BrowserTabViewController.swift index 1192e49e25..115d060257 100644 --- a/DuckDuckGo/Tab/View/BrowserTabViewController.swift +++ b/DuckDuckGo/Tab/View/BrowserTabViewController.swift @@ -114,6 +114,10 @@ final class BrowserTabViewController: NSViewController { object: nil) #if DBP + NotificationCenter.default.addObserver(self, + selector: #selector(onDBPFeatureDisabled), + name: .dbpWasDisabled, + object: nil) NotificationCenter.default.addObserver(self, selector: #selector(onCloseDataBrokerProtection), name: .dbpDidClose, @@ -165,6 +169,11 @@ final class BrowserTabViewController: NSViewController { } #if DBP + @objc + private func onDBPFeatureDisabled(_ notification: Notification) { + tabCollectionViewModel.removeAll(with: .dataBrokerProtection) + } + @objc private func onCloseDataBrokerProtection(_ notification: Notification) { guard let activeTab = tabCollectionViewModel.selectedTabViewModel?.tab, diff --git a/DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift b/DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift index cf0c70d754..25e76760dc 100644 --- a/DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift +++ b/DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift @@ -361,6 +361,16 @@ final class TabCollectionViewModel: NSObject { // MARK: - Removal + func removeAll(with content: Tab.TabContent) { + let tabs = tabCollection.tabs.filter { $0.content == content } + + for tab in tabs { + if let index = indexInAllTabs(of: tab) { + remove(at: index) + } + } + } + func remove(at index: TabIndex, published: Bool = true, forceChange: Bool = false) { switch index { case .unpinned(let i):