Skip to content

Commit d507006

Browse files
authored
Fall back to the top level tier when mapping subscriptions (#4045)
1 parent 2d8fd31 commit d507006

File tree

1 file changed

+8
-1
lines changed
  • modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync

1 file changed

+8
-1
lines changed

modules/services/servers/src/main/java/au/com/shiftyjelly/pocketcasts/servers/sync/SubscriptionModel.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@ fun SubscriptionStatusResponse.toSubscription(): Subscription? {
4040
}
4141

4242
val subscriptionResponse = subscriptions?.getOrNull(index) ?: fallbackSubscription
43+
// Some older accounts use an empty string for the subscription tier inside their subscriptions.
44+
// In these cases, the correct tier is only available at the top-level subscription status object.
45+
//
46+
// Therefore, we need to explicitly fall back to the top level object.
47+
val tier = subscriptionResponse.tier
48+
?.takeUnless(String::isNullOrBlank)
49+
?: fallbackSubscription.tier
4350

4451
return Subscription(
45-
tier = when (subscriptionResponse.tier?.lowercase()) {
52+
tier = when (tier?.lowercase()) {
4653
"plus" -> SubscriptionTier.Plus
4754
"patron" -> SubscriptionTier.Patron
4855
else -> return null

0 commit comments

Comments
 (0)