Просмотр исходного кода

Avoids overwriting a trial in progress

main
Eric Amodio 1 год назад
Родитель
Сommit
fa693a2813
2 измененных файлов: 23 добавлений и 4 удалений
  1. +10
    -4
      src/plus/subscription/subscriptionService.ts
  2. +13
    -0
      src/subscription.ts

+ 10
- 4
src/plus/subscription/subscriptionService.ts Просмотреть файл

@ -36,6 +36,7 @@ import {
getSubscriptionTimeRemaining, getSubscriptionTimeRemaining,
getTimeRemaining, getTimeRemaining,
isSubscriptionExpired, isSubscriptionExpired,
isSubscriptionInProTrial,
isSubscriptionPaid, isSubscriptionPaid,
isSubscriptionTrial, isSubscriptionTrial,
SubscriptionPlanId, SubscriptionPlanId,
@ -467,6 +468,9 @@ export class SubscriptionService implements Disposable {
return; return;
} }
// Don't overwrite a trial that is already in progress
if (isSubscriptionInProTrial(this._subscription)) return;
const startedOn = new Date(); const startedOn = new Date();
let days: number; let days: number;
@ -658,7 +662,11 @@ export class SubscriptionService implements Disposable {
SubscriptionPlanId.FreePlus, SubscriptionPlanId.FreePlus,
false, false,
undefined, undefined,
data.user.firstGitLensCheckIn != null ? new Date(data.user.firstGitLensCheckIn) : undefined,
data.user.firstGitLensCheckIn != null
? new Date(data.user.firstGitLensCheckIn)
: data.user.createdDate != null
? new Date(data.user.createdDate)
: undefined,
); );
} }
@ -685,9 +693,7 @@ export class SubscriptionService implements Disposable {
); );
} }
if (effective == null) {
effective = { ...actual };
} else if (getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id)) {
if (effective == null || getSubscriptionPlanPriority(actual.id) >= getSubscriptionPlanPriority(effective.id)) {
effective = { ...actual }; effective = { ...actual };
} }

+ 13
- 0
src/subscription.ts Просмотреть файл

@ -206,6 +206,19 @@ export function isSubscriptionTrial(subscription: Optional
return subscription.plan.actual.id !== subscription.plan.effective.id; return subscription.plan.actual.id !== subscription.plan.effective.id;
} }
export function isSubscriptionInProTrial(subscription: Optional<Subscription, 'state'>): boolean {
if (
subscription.account == null ||
!isSubscriptionTrial(subscription) ||
isSubscriptionPreviewTrialExpired(subscription) === false
) {
return false;
}
const remaining = getSubscriptionTimeRemaining(subscription);
return remaining != null ? remaining <= 0 : true;
}
export function isSubscriptionPreviewTrialExpired(subscription: Optional<Subscription, 'state'>): boolean | undefined { export function isSubscriptionPreviewTrialExpired(subscription: Optional<Subscription, 'state'>): boolean | undefined {
const remaining = getTimeRemaining(subscription.previewTrial?.expiresOn); const remaining = getTimeRemaining(subscription.previewTrial?.expiresOn);
return remaining != null ? remaining <= 0 : undefined; return remaining != null ? remaining <= 0 : undefined;

Загрузка…
Отмена
Сохранить