Skip to content

Commit

Permalink
Implement sign-out flow for DBP
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaemepereira committed Dec 27, 2023
1 parent 3e020ba commit c3af223
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions DuckDuckGo/DBP/DataBrokerProtectionFeatureDisabler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -40,6 +44,8 @@ struct DataBrokerProtectionFeatureDisabler: DataBrokerProtectionFeatureDisabling
scheduler.disableLoginItem()

dataManager.removeAllData()

NotificationCenter.default.post(name: .dbpWasDisabled, object: nil)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ final class DataBrokerProtectionSubscriptionEventHandler {

private let accountManager: Subscription.AccountManaging
private let authRepository: AuthenticationRepository
private let featureDisabler: DataBrokerProtectionFeatureDisabling

init(accountManager: Subscription.AccountManaging = Subscription.AccountManager(),
authRepository: AuthenticationRepository = KeychainAuthenticationData()) {
init(accountManager: Subscription.AccountManaging = AccountManager(),
authRepository: AuthenticationRepository = KeychainAuthenticationData(),
featureDisabler: DataBrokerProtectionFeatureDisabling = DataBrokerProtectionFeatureDisabler()) {
self.accountManager = accountManager
self.authRepository = authRepository
self.featureDisabler = featureDisabler
}

func registerForSubscriptionAccountManagerEvents() {
Expand All @@ -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()
}
}

Expand Down
9 changes: 9 additions & 0 deletions DuckDuckGo/Tab/View/BrowserTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit c3af223

Please sign in to comment.