Skip to content

Commit

Permalink
Add additional RMF attributes (#2949)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/414235014887631/1207570098166807/f
Tech Design URL:
CC:

Description:

This PR adds support for new RMF attributes.
  • Loading branch information
samsymons authored Jun 14, 2024
1 parent 0196523 commit f176448
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9770,7 +9770,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 153.0.0;
version = "153.0.0-1";
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "b78ae617c7fe66244741f489158a1f40e567e674",
"version" : "153.0.0"
"revision" : "aadce5cb02cdbf0b3dbbe846bca997abf1506dbe",
"version" : "153.0.0-1"
}
},
{
Expand Down
24 changes: 23 additions & 1 deletion DuckDuckGo/RemoteMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ struct RemoteMessaging {

var privacyProDaysSinceSubscribed: Int = -1
var privacyProDaysUntilExpiry: Int = -1
var privacyProPurchasePlatform: String?
var privacyProIsActive: Bool = false
var privacyProIsExpiring: Bool = false
var privacyProIsExpired: Bool = false
let surveyActionMapper: DefaultRemoteMessagingSurveyURLBuilder

if let accessToken = AppDependencyProvider.shared.subscriptionManager.accountManager.accessToken {
Expand All @@ -173,6 +177,20 @@ struct RemoteMessaging {
if case let .success(subscription) = subscriptionResult {
privacyProDaysSinceSubscribed = Calendar.current.numberOfDaysBetween(subscription.startedAt, and: Date()) ?? -1
privacyProDaysUntilExpiry = Calendar.current.numberOfDaysBetween(Date(), and: subscription.expiresOrRenewsAt) ?? -1
privacyProPurchasePlatform = subscription.platform.rawValue

switch subscription.status {
case .autoRenewable, .gracePeriod:
privacyProIsActive = true
case .notAutoRenewable:
privacyProIsActive = true
privacyProIsExpiring = true
case .expired, .inactive:
privacyProIsExpired = true
case .unknown:
break // Not supported in RMF
}

surveyActionMapper = DefaultRemoteMessagingSurveyURLBuilder(statisticsStore: statisticsStore, subscription: subscription)
} else {
surveyActionMapper = DefaultRemoteMessagingSurveyURLBuilder(statisticsStore: statisticsStore, subscription: nil)
Expand All @@ -195,7 +213,11 @@ struct RemoteMessaging {
isPrivacyProEligibleUser: canPurchase,
isPrivacyProSubscriber: isPrivacyProSubscriber,
privacyProDaysSinceSubscribed: privacyProDaysSinceSubscribed,
privacyProDaysUntilExpiry: privacyProDaysUntilExpiry),
privacyProDaysUntilExpiry: privacyProDaysUntilExpiry,
privacyProPurchasePlatform: privacyProPurchasePlatform,
isPrivacyProSubscriptionActive: privacyProIsActive,
isPrivacyProSubscriptionExpiring: privacyProIsExpiring,
isPrivacyProSubscriptionExpired: privacyProIsExpired),
percentileStore: RemoteMessagingPercentileUserDefaultsStore(userDefaults: .standard),
surveyActionMapper: surveyActionMapper,
dismissedMessageIds: remoteMessagingStore.fetchDismissedRemoteMessageIds()
Expand Down
6 changes: 5 additions & 1 deletion DuckDuckGoTests/RemoteMessagingStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ class RemoteMessagingStoreTests: XCTestCase {
isPrivacyProEligibleUser: false,
isPrivacyProSubscriber: false,
privacyProDaysSinceSubscribed: -1,
privacyProDaysUntilExpiry: -1),
privacyProDaysUntilExpiry: -1,
privacyProPurchasePlatform: nil,
isPrivacyProSubscriptionActive: false,
isPrivacyProSubscriptionExpiring: false,
isPrivacyProSubscriptionExpired: false),
percentileStore: RemoteMessagingPercentileUserDefaultsStore(userDefaults: self.defaults),
surveyActionMapper: MockRemoteMessagingSurveyActionMapper(),
dismissedMessageIds: []
Expand Down

0 comments on commit f176448

Please sign in to comment.