Skip to content

Commit

Permalink
Update labels for clarity and add PIR checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed May 24, 2024
1 parent 7798f7b commit e723c05
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
22 changes: 17 additions & 5 deletions DuckDuckGo/Common/Surveys/SurveyRemoteMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging {
private let messageStorage: SurveyRemoteMessagingStorage
private let accountManager: AccountManaging
private let subscriptionFetcher: SurveyRemoteMessageSubscriptionFetching
private let waitlistActivationDateStore: WaitlistActivationDateStore
private let vpnActivationDateStore: WaitlistActivationDateStore
private let pirActivationDateStore: WaitlistActivationDateStore
private let minimumRefreshInterval: TimeInterval
private let userDefaults: UserDefaults

Expand All @@ -70,7 +71,8 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging {
messageStorage: SurveyRemoteMessagingStorage = DefaultSurveyRemoteMessagingStorage.surveys(),
accountManager: AccountManaging,
subscriptionFetcher: SurveyRemoteMessageSubscriptionFetching,
waitlistActivationDateStore: WaitlistActivationDateStore = DefaultWaitlistActivationDateStore(source: .netP),
vpnActivationDateStore: WaitlistActivationDateStore = DefaultWaitlistActivationDateStore(source: .netP),
pirActivationDateStore: WaitlistActivationDateStore = DefaultWaitlistActivationDateStore(source: .dbp),
networkProtectionVisibility: NetworkProtectionFeatureVisibility = DefaultNetworkProtectionVisibility(subscriptionManager: Application.appDelegate.subscriptionManager),
minimumRefreshInterval: TimeInterval,
userDefaults: UserDefaults = .standard
Expand All @@ -79,7 +81,8 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging {
self.messageStorage = messageStorage
self.accountManager = accountManager
self.subscriptionFetcher = subscriptionFetcher
self.waitlistActivationDateStore = waitlistActivationDateStore
self.vpnActivationDateStore = vpnActivationDateStore
self.pirActivationDateStore = pirActivationDateStore
self.minimumRefreshInterval = minimumRefreshInterval
self.userDefaults = userDefaults
}
Expand Down Expand Up @@ -188,8 +191,17 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging {
}

// Check VPN usage:
if let requiredDaysSinceActivation = message.attributes.daysSinceVPNEnabled {
if let daysSinceActivation = waitlistActivationDateStore.daysSinceActivation(), requiredDaysSinceActivation <= daysSinceActivation {
if let requiredDaysSinceVPNActivation = message.attributes.daysSinceVPNEnabled {
if let daysSinceActivation = vpnActivationDateStore.daysSinceActivation(), requiredDaysSinceVPNActivation <= daysSinceActivation {
attributeMatchStatus = true
} else {
return false
}
}

// Check PIR usage:
if let requiredDaysSincePIRActivation = message.attributes.daysSincePIREnabled {
if let daysSinceActivation = pirActivationDateStore.daysSinceActivation(), requiredDaysSincePIRActivation <= daysSinceActivation {
attributeMatchStatus = true
} else {
return false
Expand Down
18 changes: 12 additions & 6 deletions UnitTests/HomePage/SurveyRemoteMessagingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ final class SurveyRemoteMessagingTests: XCTestCase {
messageStorage: storage,
accountManager: accountManager,
subscriptionFetcher: subscriptionFetcher,
waitlistActivationDateStore: activationDateStorage,
vpnActivationDateStore: activationDateStorage,
pirActivationDateStore: activationDateStorage,
minimumRefreshInterval: 0,
userDefaults: defaults
)
Expand All @@ -71,7 +72,8 @@ final class SurveyRemoteMessagingTests: XCTestCase {
messageStorage: storage,
accountManager: accountManager,
subscriptionFetcher: subscriptionFetcher,
waitlistActivationDateStore: activationDateStorage,
vpnActivationDateStore: activationDateStorage,
pirActivationDateStore: activationDateStorage,
minimumRefreshInterval: 0,
userDefaults: defaults
)
Expand All @@ -98,7 +100,8 @@ final class SurveyRemoteMessagingTests: XCTestCase {
messageStorage: storage,
accountManager: accountManager,
subscriptionFetcher: subscriptionFetcher,
waitlistActivationDateStore: activationDateStorage,
vpnActivationDateStore: activationDateStorage,
pirActivationDateStore: activationDateStorage,
minimumRefreshInterval: 0,
userDefaults: defaults
)
Expand Down Expand Up @@ -126,7 +129,8 @@ final class SurveyRemoteMessagingTests: XCTestCase {
messageStorage: storage,
accountManager: accountManager,
subscriptionFetcher: subscriptionFetcher,
waitlistActivationDateStore: activationDateStorage,
vpnActivationDateStore: activationDateStorage,
pirActivationDateStore: activationDateStorage,
minimumRefreshInterval: .days(7), // Use a large number to hit the refresh check
userDefaults: defaults
)
Expand Down Expand Up @@ -154,7 +158,8 @@ final class SurveyRemoteMessagingTests: XCTestCase {
messageStorage: storage,
accountManager: accountManager,
subscriptionFetcher: subscriptionFetcher,
waitlistActivationDateStore: activationDateStorage,
vpnActivationDateStore: activationDateStorage,
pirActivationDateStore: activationDateStorage,
minimumRefreshInterval: 0,
userDefaults: defaults
)
Expand All @@ -179,7 +184,8 @@ final class SurveyRemoteMessagingTests: XCTestCase {
messageStorage: storage,
accountManager: accountManager,
subscriptionFetcher: subscriptionFetcher,
waitlistActivationDateStore: activationDateStorage,
vpnActivationDateStore: activationDateStorage,
pirActivationDateStore: activationDateStorage,
minimumRefreshInterval: 0,
userDefaults: defaults
)
Expand Down

0 comments on commit e723c05

Please sign in to comment.