Skip to content

Commit

Permalink
Add delegate calls to check user authentication state
Browse files Browse the repository at this point in the history
  • Loading branch information
aataraxiaa committed Sep 22, 2024
1 parent 812f901 commit aa8afa2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions DuckDuckGo/DBP/DataBrokerProtectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ public final class DataBrokerProtectionManager {
}

extension DataBrokerProtectionManager: DataBrokerProtectionDataManagerDelegate {

public func dataBrokerProtectionDataManagerDidUpdateData() {
loginItemInterface.profileSaved()
}

public func dataBrokerProtectionDataManagerDidDeleteData() {
loginItemInterface.dataDeleted()
}

public func isAuthenticatedUser() -> Bool {
isUserAuthenticated()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public protocol DataBrokerProtectionDataManaging {
public protocol DataBrokerProtectionDataManagerDelegate: AnyObject {
func dataBrokerProtectionDataManagerDidUpdateData()
func dataBrokerProtectionDataManagerDidDeleteData()
func isAuthenticatedUser() -> Bool
}

public class DataBrokerProtectionDataManager: DataBrokerProtectionDataManaging {
Expand Down Expand Up @@ -200,6 +201,7 @@ private extension DataBrokerProtectionDataManager {
}

extension DataBrokerProtectionDataManager: InMemoryDataCacheDelegate {

public func saveCachedProfileToDatabase(_ profile: DataBrokerProtectionProfile) async throws {
try await saveProfile(profile)

Expand All @@ -212,11 +214,16 @@ extension DataBrokerProtectionDataManager: InMemoryDataCacheDelegate {

delegate?.dataBrokerProtectionDataManagerDidDeleteData()
}

public func isAuthenticatedUser() -> Bool {
delegate?.isAuthenticatedUser() ?? true
}
}

public protocol InMemoryDataCacheDelegate: AnyObject {
func saveCachedProfileToDatabase(_ profile: DataBrokerProtectionProfile) async throws
func removeAllData() throws
func isAuthenticatedUser() -> Bool
}

public final class InMemoryDataCache {
Expand All @@ -238,6 +245,12 @@ public final class InMemoryDataCache {
}

extension InMemoryDataCache: DBPUICommunicationDelegate {

func getHandshakeUserData() -> DBPUIHandshakeUserData? {
let isAuthenticatedUser = delegate?.isAuthenticatedUser() ?? true
return DBPUIHandshakeUserData(isAuthenticatedUser: isAuthenticatedUser)
}

func saveProfile() async throws {
guard let profile = profile else { return }
try await delegate?.saveCachedProfileToDatabase(profile)
Expand Down

0 comments on commit aa8afa2

Please sign in to comment.