@@ -1,4 +1,5 @@
|
||||
import { type CreateCheckoutSessionInput } from '@affine/graphql';
|
||||
import { mixpanel } from '@affine/track';
|
||||
import { OnEvent, Service } from '@toeverything/infra';
|
||||
|
||||
import { Subscription } from '../entities/subscription';
|
||||
@@ -13,6 +14,22 @@ export class SubscriptionService extends Service {
|
||||
|
||||
constructor(private readonly store: SubscriptionStore) {
|
||||
super();
|
||||
this.subscription.ai$
|
||||
.map(sub => !!sub)
|
||||
.distinctUntilChanged()
|
||||
.subscribe(ai => {
|
||||
mixpanel.people.set({
|
||||
ai,
|
||||
});
|
||||
});
|
||||
this.subscription.pro$
|
||||
.map(sub => !!sub)
|
||||
.distinctUntilChanged()
|
||||
.subscribe(pro => {
|
||||
mixpanel.people.set({
|
||||
pro,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async createCheckoutSession(input: CreateCheckoutSessionInput) {
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
import type { QuotaQuery } from '@affine/graphql';
|
||||
import { createEvent, OnEvent, Service } from '@toeverything/infra';
|
||||
import { mixpanel } from '@affine/track';
|
||||
import { OnEvent, Service } from '@toeverything/infra';
|
||||
|
||||
import { UserQuota } from '../entities/user-quota';
|
||||
import { AccountChanged } from './auth';
|
||||
|
||||
type UserQuotaInfo = NonNullable<QuotaQuery['currentUser']>['quota'];
|
||||
|
||||
export const UserQuotaChanged = createEvent<UserQuotaInfo>('UserQuotaChanged');
|
||||
|
||||
@OnEvent(AccountChanged, e => e.onAccountChanged)
|
||||
export class UserQuotaService extends Service {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.quota.quota$.distinctUntilChanged().subscribe(q => {
|
||||
this.eventBus.emit(UserQuotaChanged, q);
|
||||
});
|
||||
this.quota.quota$
|
||||
.map(q => q?.humanReadable.name)
|
||||
.distinctUntilChanged()
|
||||
.subscribe(quota => {
|
||||
mixpanel.people.set({
|
||||
quota,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
quota = this.framework.createEntity(UserQuota);
|
||||
|
||||
Reference in New Issue
Block a user