From 0f133874873939b27ab8f10b2a7b4bd9b8bde4fe Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 7 Nov 2022 16:05:31 -0500 Subject: [PATCH] Chooses actual plan if same or greater --- src/plus/subscription/subscriptionService.ts | 32 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/plus/subscription/subscriptionService.ts b/src/plus/subscription/subscriptionService.ts index 30ed70c..68d1049 100644 --- a/src/plus/subscription/subscriptionService.ts +++ b/src/plus/subscription/subscriptionService.ts @@ -615,12 +615,15 @@ export class SubscriptionService implements Disposable { let actual: Subscription['plan']['actual'] | undefined; if (paidLicenses.length > 0) { - paidLicenses.sort( - (a, b) => - licenseStatusPriority(b[1].latestStatus) - licenseStatusPriority(a[1].latestStatus) || - getSubscriptionPlanPriority(convertLicenseTypeToPlanId(b[0])) - - getSubscriptionPlanPriority(convertLicenseTypeToPlanId(a[0])), - ); + if (paidLicenses.length > 1) { + paidLicenses.sort( + (a, b) => + getSubscriptionPlanPriority(convertLicenseTypeToPlanId(b[0])) + + licenseStatusPriority(b[1].latestStatus) - + (getSubscriptionPlanPriority(convertLicenseTypeToPlanId(a[0])) + + licenseStatusPriority(a[1].latestStatus)), + ); + } const [licenseType, license] = paidLicenses[0]; actual = getSubscriptionPlan( @@ -639,12 +642,15 @@ export class SubscriptionService implements Disposable { let effective: Subscription['plan']['effective'] | undefined; if (effectiveLicenses.length > 0) { - effectiveLicenses.sort( - (a, b) => - licenseStatusPriority(b[1].latestStatus) - licenseStatusPriority(a[1].latestStatus) || - getSubscriptionPlanPriority(convertLicenseTypeToPlanId(b[0])) - - getSubscriptionPlanPriority(convertLicenseTypeToPlanId(a[0])), - ); + if (effectiveLicenses.length > 1) { + effectiveLicenses.sort( + (a, b) => + getSubscriptionPlanPriority(convertLicenseTypeToPlanId(b[0])) + + licenseStatusPriority(b[1].latestStatus) - + (getSubscriptionPlanPriority(convertLicenseTypeToPlanId(a[0])) + + licenseStatusPriority(a[1].latestStatus)), + ); + } const [licenseType, license] = effectiveLicenses[0]; effective = getSubscriptionPlan( @@ -656,6 +662,8 @@ export class SubscriptionService implements Disposable { if (effective == null) { effective = { ...actual }; + } else if (getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id)) { + effective = { ...actual }; } this.changeSubscription({