浏览代码

Fixes graph subscription access

- avoids mutating subscriptions

Co-authored-by: Eric Amodio <eamodio@gmail.com>
main
Keith Daulton 2 年前
父节点
当前提交
faea28a390
共有 2 个文件被更改,包括 33 次插入8 次删除
  1. +15
    -2
      src/git/gitProviderService.ts
  2. +18
    -6
      src/plus/subscription/subscriptionService.ts

+ 15
- 2
src/git/gitProviderService.ts 查看文件

@ -24,7 +24,12 @@ import type { SubscriptionChangeEvent } from '../plus/subscription/subscriptionS
import type { RepoComparisonKey } from '../repositories';
import { asRepoComparisonKey, Repositories } from '../repositories';
import type { FreeSubscriptionPlans, RequiredSubscriptionPlans, Subscription } from '../subscription';
import { getSubscriptionPlanPriority, isSubscriptionPaidPlan, SubscriptionPlanId } from '../subscription';
import {
getSubscriptionPlan,
getSubscriptionPlanPriority,
isSubscriptionPaidPlan,
SubscriptionPlanId,
} from '../subscription';
import { groupByFilterMap, groupByMap } from '../system/array';
import { gate } from '../system/decorators/gate';
import { debug, getLogScope, log } from '../system/decorators/log';
@ -543,7 +548,15 @@ export class GitProviderService implements Disposable {
access.visibility === RepositoryVisibility.Private &&
access.subscription.current.previewTrial == null
),
subscription: { current: access.subscription.current },
subscription: {
current: {
...access.subscription.current,
plan: {
...access.subscription.current.plan,
effective: getSubscriptionPlan(SubscriptionPlanId.Pro, undefined),
},
},
},
visibility: access.visibility,
};
}

+ 18
- 6
src/plus/subscription/subscriptionService.ts 查看文件

@ -776,16 +776,28 @@ export class SubscriptionService implements Disposable {
// Check if the preview has expired, if not apply it
if (subscription.previewTrial != null && (getTimeRemaining(subscription.previewTrial.expiresOn) ?? 0) > 0) {
(subscription.plan as PickMutable<Subscription['plan'], 'effective'>).effective = getSubscriptionPlan(
SubscriptionPlanId.Pro,
new Date(subscription.previewTrial.startedOn),
new Date(subscription.previewTrial.expiresOn),
);
subscription = {
...subscription,
plan: {
...subscription.plan,
effective: getSubscriptionPlan(
SubscriptionPlanId.Pro,
new Date(subscription.previewTrial.startedOn),
new Date(subscription.previewTrial.expiresOn),
),
},
};
}
// If the effective plan has expired, then replace it with the actual plan
if (isSubscriptionExpired(subscription)) {
(subscription.plan as PickMutable<Subscription['plan'], 'effective'>).effective = subscription.plan.actual;
subscription = {
...subscription,
plan: {
...subscription.plan,
effective: subscription.plan.actual,
},
};
}
subscription.state = computeSubscriptionState(subscription);

正在加载...
取消
保存