Skip to content

Commit 3ee22f6

Browse files
mebarbosaMiSikora
andauthored
Cherry-pick changes from #3802 (#3804)
Co-authored-by: Michał Sikora <me@mehow.io>
1 parent b72014e commit 3ee22f6

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

modules/features/profile/src/main/java/au/com/shiftyjelly/pocketcasts/profile/winback/WinbackViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class WinbackViewModel @Inject constructor(
261261
.await()
262262
}
263263

264-
private fun List<ProductDetails>.toSubscriptionPlans() = map(subscriptionMapper::mapFromProductDetails)
264+
private fun List<ProductDetails>.toSubscriptionPlans() = map { productDetails -> subscriptionMapper.mapFromProductDetails(productDetails, removeWinbackOffer = false) }
265265
.filterIsInstance<Subscription.Simple>()
266266
.map(Subscription.Simple::toPlan)
267267
.sortedWith(PlanComparator)

modules/services/model/src/main/java/au/com/shiftyjelly/pocketcasts/models/type/SubscriptionMapper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ class SubscriptionMapper @Inject constructor() {
1313
productDetails: ProductDetails,
1414
isOfferEligible: Boolean = false,
1515
referralProductDetails: ReferralProductDetails? = null,
16+
removeWinbackOffer: Boolean = true,
1617
): Subscription? {
1718
val matchingSubscriptionOfferDetails = if (isOfferEligible || referralProductDetails != null) {
1819
productDetails
1920
.subscriptionOfferDetails
2021
?.filter { referralProductDetails == null && !it.offerTags.contains(REFERRAL_OFFER_TAG) } // get SubscriptionOfferDetails with offers
22+
?.filter { if (removeWinbackOffer) !it.offerTags.contains(WINBACK_OFFER_TAG) else true }
2123
?.filter { it.offerSubscriptionPricingPhase != null } // get SubscriptionOfferDetails with offers
2224
?.ifEmpty { productDetails.subscriptionOfferDetails } // if no special offers, return all offers available
2325
?: productDetails.subscriptionOfferDetails // if null, return all offers
@@ -32,6 +34,7 @@ class SubscriptionMapper @Inject constructor() {
3234
} else {
3335
matchingSubscriptionOfferDetails
3436
.filter { !it.offerTags.contains(REFERRAL_OFFER_TAG) }
37+
.filter { if (removeWinbackOffer) !it.offerTags.contains(WINBACK_OFFER_TAG) else true }
3538
// This assumes that base plan has lowest number of pricing phases,
3639
// and if something else has the same number of phases,
3740
// base plan will be the first one
@@ -163,5 +166,6 @@ class SubscriptionMapper @Inject constructor() {
163166

164167
companion object {
165168
private const val REFERRAL_OFFER_TAG = "referral-offer"
169+
private const val WINBACK_OFFER_TAG = "winback"
166170
}
167171
}

modules/services/repositories/src/test/java/au/com/shiftyjelly/pocketcasts/repositories/referrals/ReferralOfferInfoProviderTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class ReferralOfferInfoProviderTest {
9595
whenever(productDetails.subscriptionOfferDetails).thenReturn(listOf(subscriptionOfferDetails))
9696
whenever(subscription.productDetails).thenReturn(productDetails)
9797
whenever(subscriptionOfferDetails.offerId).thenReturn(offerId)
98-
whenever(subscriptionMapper.mapFromProductDetails(eq(productDetails), anyBoolean(), any())).thenReturn(subscription)
98+
whenever(subscriptionMapper.mapFromProductDetails(eq(productDetails), anyBoolean(), any(), any())).thenReturn(subscription)
9999

100100
return ProductDetailsState.Loaded(listOf(productDetails))
101101
}

0 commit comments

Comments
 (0)