diff --git a/Sources/RemoteMessaging/Mappers/JsonToRemoteMessageModelMapper.swift b/Sources/RemoteMessaging/Mappers/JsonToRemoteMessageModelMapper.swift index 725d1b979..6aa03208f 100644 --- a/Sources/RemoteMessaging/Mappers/JsonToRemoteMessageModelMapper.swift +++ b/Sources/RemoteMessaging/Mappers/JsonToRemoteMessageModelMapper.swift @@ -43,6 +43,7 @@ private enum AttributesKey: String, CaseIterable { case pproPurchasePlatform case pproSubscriptionStatus case interactedWithMessage + case interactedWithDeprecatedMacRemoteMessage case installedMacAppStore case pinnedTabs case customHomePage @@ -74,6 +75,9 @@ private enum AttributesKey: String, CaseIterable { case .pproPurchasePlatform: return PrivacyProPurchasePlatformMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute) case .pproSubscriptionStatus: return PrivacyProSubscriptionStatusMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute) case .interactedWithMessage: return InteractedWithMessageMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute) + case .interactedWithDeprecatedMacRemoteMessage: return InteractedWithDeprecatedMacRemoteMessageMatchingAttribute( + jsonMatchingAttribute: jsonMatchingAttribute + ) case .installedMacAppStore: return IsInstalledMacAppStoreMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute) case .pinnedTabs: return PinnedTabsMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute) case .customHomePage: return CustomHomePageMatchingAttribute(jsonMatchingAttribute: jsonMatchingAttribute) diff --git a/Sources/RemoteMessaging/Matchers/UserAttributeMatcher.swift b/Sources/RemoteMessaging/Matchers/UserAttributeMatcher.swift index 1c452dbdd..973fcf7c5 100644 --- a/Sources/RemoteMessaging/Matchers/UserAttributeMatcher.swift +++ b/Sources/RemoteMessaging/Matchers/UserAttributeMatcher.swift @@ -94,6 +94,7 @@ public struct DesktopUserAttributeMatcher: AttributeMatching { private let hasCustomHomePage: Bool private let isDuckPlayerOnboarded: Bool private let isDuckPlayerEnabled: Bool + private let dismissedDeprecatedMacRemoteMessageIds: [String] private let commonUserAttributeMatcher: CommonUserAttributeMatcher @@ -116,12 +117,14 @@ public struct DesktopUserAttributeMatcher: AttributeMatching { pinnedTabsCount: Int, hasCustomHomePage: Bool, isDuckPlayerOnboarded: Bool, - isDuckPlayerEnabled: Bool + isDuckPlayerEnabled: Bool, + dismissedDeprecatedMacRemoteMessageIds: [String] ) { self.pinnedTabsCount = pinnedTabsCount self.hasCustomHomePage = hasCustomHomePage self.isDuckPlayerOnboarded = isDuckPlayerOnboarded self.isDuckPlayerEnabled = isDuckPlayerEnabled + self.dismissedDeprecatedMacRemoteMessageIds = dismissedDeprecatedMacRemoteMessageIds commonUserAttributeMatcher = .init( statisticsStore: statisticsStore, @@ -153,6 +156,14 @@ public struct DesktopUserAttributeMatcher: AttributeMatching { return matchingAttribute.evaluate(for: isDuckPlayerOnboarded) case let matchingAttribute as DuckPlayerEnabledMatchingAttribute: return matchingAttribute.evaluate(for: isDuckPlayerEnabled) + case let matchingAttribute as InteractedWithDeprecatedMacRemoteMessageMatchingAttribute: + if dismissedDeprecatedMacRemoteMessageIds.contains(where: { messageId in + StringArrayMatchingAttribute(matchingAttribute.value).matches(value: messageId) == .match + }) { + return .match + } else { + return .fail + } default: return commonUserAttributeMatcher.evaluate(matchingAttribute: matchingAttribute) } diff --git a/Sources/RemoteMessaging/Model/MatchingAttributes.swift b/Sources/RemoteMessaging/Model/MatchingAttributes.swift index a423eb513..4a98b63ba 100644 --- a/Sources/RemoteMessaging/Model/MatchingAttributes.swift +++ b/Sources/RemoteMessaging/Model/MatchingAttributes.swift @@ -159,6 +159,11 @@ struct InteractedWithMessageMatchingAttribute: SingleValueMatching { var fallback: Bool? } +struct InteractedWithDeprecatedMacRemoteMessageMatchingAttribute: SingleValueMatching { + var value: [String]? = [] + var fallback: Bool? +} + struct IsInstalledMacAppStoreMatchingAttribute: SingleValueMatching { var value: Bool? var fallback: Bool? diff --git a/Tests/RemoteMessagingTests/Matchers/DesktopUserAttributeMatcherTests.swift b/Tests/RemoteMessagingTests/Matchers/DesktopUserAttributeMatcherTests.swift index 0a329bc8a..f345f8393 100644 --- a/Tests/RemoteMessagingTests/Matchers/DesktopUserAttributeMatcherTests.swift +++ b/Tests/RemoteMessagingTests/Matchers/DesktopUserAttributeMatcherTests.swift @@ -51,7 +51,7 @@ class DesktopUserAttributeMatcherTests: XCTestCase { emailManagerStorage.mockToken = "token" emailManager = EmailManager(storage: emailManagerStorage) - setUpUserAttributeMatcher() + setUpUserAttributeMatcher(dismissedDeprecatedMacRemoteMessageIds: ["dismissed-message"]) } override func tearDownWithError() throws { @@ -133,9 +133,37 @@ class DesktopUserAttributeMatcherTests: XCTestCase { .fail) } + // MARK: - DeprecatedMacRemoteMessage + + func testWhenNoDismissedMessageIdsAreProvidedThenReturnFail() throws { + XCTAssertEqual(matcher.evaluate( + matchingAttribute: InteractedWithDeprecatedMacRemoteMessageMatchingAttribute(value: [], fallback: nil) + ), .fail) + } + + func testWhenNoDismissedMessageIdsMatchThenReturnFail() throws { + XCTAssertEqual(matcher.evaluate( + matchingAttribute: InteractedWithDeprecatedMacRemoteMessageMatchingAttribute(value: ["unrelated-message"], fallback: nil) + ), .fail) + } + + func testWhenOneDismissedMessageIdMatchesThenReturnMatch() throws { + XCTAssertEqual(matcher.evaluate( + matchingAttribute: InteractedWithDeprecatedMacRemoteMessageMatchingAttribute(value: ["dismissed-message"], fallback: nil) + ), .match) + } + + func testWhenTwoDismissedMessageIdsMatchThenReturnMatch() throws { + XCTAssertEqual(matcher.evaluate( + matchingAttribute: InteractedWithDeprecatedMacRemoteMessageMatchingAttribute(value: [ + "dismissed-message", "unrelated-message" + ], fallback: nil) + ), .match) + } + // MARK: - - private func setUpUserAttributeMatcher(dismissedMessageIds: [String] = []) { + private func setUpUserAttributeMatcher(dismissedMessageIds: [String] = [], dismissedDeprecatedMacRemoteMessageIds: [String] = []) { matcher = DesktopUserAttributeMatcher( statisticsStore: mockStatisticsStore, variantManager: manager, @@ -156,7 +184,8 @@ class DesktopUserAttributeMatcherTests: XCTestCase { pinnedTabsCount: 3, hasCustomHomePage: true, isDuckPlayerOnboarded: true, - isDuckPlayerEnabled: false + isDuckPlayerEnabled: false, + dismissedDeprecatedMacRemoteMessageIds: dismissedDeprecatedMacRemoteMessageIds ) } }