From c1e3e53f9b0c9bba6338c3ce480113f44525f70d Mon Sep 17 00:00:00 2001 From: saquib-adobe Date: Wed, 6 Nov 2024 00:48:15 +0530 Subject: [PATCH] Updated the toPropositionsList to toUniquePropositionsList --- .../mobile/optimize/OfferExtension.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OfferExtension.kt b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OfferExtension.kt index f1b880e..2aba614 100644 --- a/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OfferExtension.kt +++ b/code/optimize/src/main/java/com/adobe/marketing/mobile/optimize/OfferExtension.kt @@ -19,18 +19,20 @@ object OfferExtension { fun List?.generateDisplayInteractionXdm(): Map? { return OptimizeUtils.generateInteractionXdm( OptimizeConstants.JsonValues.EE_EVENT_TYPE_PROPOSITION_DISPLAY, - this?.toPropositionsList() + this?.toUniquePropositionsList() ) } - private fun List?.toPropositionsList(): List? { - val propositions = this - ?.mapNotNull { it.propositionReference?.get() } - .takeIf { !it.isNullOrEmpty() } - return propositions?.filter { proposition -> - proposition.offers.any { offerInProp -> - this?.any { it.id == offerInProp.id } == true - } - } + private fun List?.toUniquePropositionsList(): List? { + if (this.isNullOrEmpty()) return null + val seenPropsIds = mutableSetOf() + val offerIds = this.mapNotNull { it.id }.toSet() + return this + .mapNotNull { it.propositionReference?.get() } + .filter { proposition -> + with(proposition) { + id !in seenPropsIds && offers.any { it.id in offerIds } + } + }.onEach { seenPropsIds.add(it.id) } } }