Skip to content

Commit

Permalink
Check all attributes when matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed May 24, 2024
1 parent ca90535 commit 03a8c13
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions DuckDuckGo/Common/Surveys/SurveyRemoteMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,16 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging {

return messages.filter { message in

// TODO: Make it so that we check all attributes, not just the first one
var didMatch = false
var attributeMatchStatus = false

// Check subscription status:
if let messageSubscriptionStatus = message.attributes.subscriptionStatus {
if let subscriptionStatus = Subscription.Status(rawValue: messageSubscriptionStatus) {
return subscription.status == subscriptionStatus
if subscription.status == subscriptionStatus {
attributeMatchStatus = true
} else {
return false
}
} else {
// If we received a subscription status but can't map it to a valid type, don't show the message.
return false
Expand All @@ -142,7 +145,11 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging {
// Check subscription billing period:
if let messageSubscriptionBillingPeriod = message.attributes.subscriptionBillingPeriod {
if let subscriptionBillingPeriod = Subscription.BillingPeriod(rawValue: messageSubscriptionBillingPeriod) {
return subscription.billingPeriod == subscriptionBillingPeriod
if subscription.billingPeriod == subscriptionBillingPeriod {
attributeMatchStatus = true
} else {
return false
}
} else {
// If we received a subscription billing period but can't map it to a valid type, don't show the message.
return false
Expand All @@ -157,7 +164,11 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging {
return false
}

return daysSinceSubscriptionStartDate >= messageDaysSinceSubscriptionStarted
if daysSinceSubscriptionStartDate >= messageDaysSinceSubscriptionStarted {
attributeMatchStatus = true
} else {
return false
}
}

// Check subscription end/expiration date:
Expand All @@ -168,20 +179,23 @@ final class DefaultSurveyRemoteMessaging: SurveyRemoteMessaging {
return false
}

return daysUntilSubscriptionExpiration <= messageDaysUntilSubscriptionExpiration
if daysUntilSubscriptionExpiration <= messageDaysUntilSubscriptionExpiration {
attributeMatchStatus = true
} else {
return false
}
}

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

// Don't show messages unless at least one attribute matches:
return false
return attributeMatchStatus

}
}
Expand Down

0 comments on commit 03a8c13

Please sign in to comment.