feat(core): add notifications settings (#11004)

This commit is contained in:
EYHN
2025-03-20 03:52:56 +00:00
parent 46ed76ecb0
commit 120e193c58
14 changed files with 334 additions and 6 deletions
@@ -24,6 +24,10 @@ export { SubscriptionService } from './services/subscription';
export { UserCopilotQuotaService } from './services/user-copilot-quota';
export { UserFeatureService } from './services/user-feature';
export { UserQuotaService } from './services/user-quota';
export {
type UserSettings,
UserSettingsService,
} from './services/user-settings';
export { WorkspaceInvoicesService } from './services/workspace-invoices';
export { WorkspaceServerService } from './services/workspace-server';
export { WorkspaceSubscriptionService } from './services/workspace-subscription';
@@ -71,6 +75,7 @@ import { SubscriptionService } from './services/subscription';
import { UserCopilotQuotaService } from './services/user-copilot-quota';
import { UserFeatureService } from './services/user-feature';
import { UserQuotaService } from './services/user-quota';
import { UserSettingsService } from './services/user-settings';
import { WorkspaceInvoicesService } from './services/workspace-invoices';
import { WorkspaceServerService } from './services/workspace-server';
import { WorkspaceSubscriptionService } from './services/workspace-subscription';
@@ -88,6 +93,7 @@ import { SubscriptionStore } from './stores/subscription';
import { UserCopilotQuotaStore } from './stores/user-copilot-quota';
import { UserFeatureStore } from './stores/user-feature';
import { UserQuotaStore } from './stores/user-quota';
import { UserSettingsStore } from './stores/user-settings';
export function configureCloudModule(framework: Framework) {
configureDefaultAuthProvider(framework);
@@ -150,7 +156,9 @@ export function configureCloudModule(framework: Framework) {
.service(AcceptInviteService, [AcceptInviteStore, InviteInfoStore])
.store(AcceptInviteStore, [GraphQLService])
.service(PublicUserService, [PublicUserStore])
.store(PublicUserStore, [GraphQLService]);
.store(PublicUserStore, [GraphQLService])
.service(UserSettingsService, [UserSettingsStore])
.store(UserSettingsStore, [GraphQLService]);
framework
.scope(WorkspaceScope)
@@ -0,0 +1,62 @@
import {
effect,
exhaustMapWithTrailing,
fromPromise,
LiveData,
onComplete,
onStart,
Service,
smartRetry,
} from '@toeverything/infra';
import { catchError, EMPTY, mergeMap } from 'rxjs';
import type {
UpdateUserSettingsInput,
UserSettings,
UserSettingsStore,
} from '../stores/user-settings';
export type { UserSettings };
export class UserSettingsService extends Service {
constructor(private readonly store: UserSettingsStore) {
super();
}
userSettings$ = new LiveData<UserSettings | undefined>(undefined);
isLoading$ = new LiveData<boolean>(false);
error$ = new LiveData<any | undefined>(undefined);
revalidate = effect(
exhaustMapWithTrailing(() => {
return fromPromise(() => {
return this.store.getUserSettings();
}).pipe(
smartRetry(),
mergeMap(settings => {
this.userSettings$.value = settings;
return EMPTY;
}),
catchError(error => {
this.error$.value = error;
return EMPTY;
}),
onStart(() => {
this.isLoading$.value = true;
}),
onComplete(() => {
this.isLoading$.value = false;
})
);
})
);
async updateUserSettings(settings: UpdateUserSettingsInput) {
await this.store.updateUserSettings(settings);
this.userSettings$.value = {
...this.userSettings$.value,
...(settings as UserSettings),
};
this.revalidate();
}
}
@@ -0,0 +1,37 @@
import {
type GetUserSettingsQuery,
getUserSettingsQuery,
type UpdateSettingsInput,
updateUserSettingsMutation,
} from '@affine/graphql';
import { Store } from '@toeverything/infra';
import type { GraphQLService } from '../services/graphql';
export type UserSettings = NonNullable<
GetUserSettingsQuery['currentUser']
>['settings'];
export type UpdateUserSettingsInput = UpdateSettingsInput;
export class UserSettingsStore extends Store {
constructor(private readonly gqlService: GraphQLService) {
super();
}
async getUserSettings(): Promise<UserSettings | undefined> {
const result = await this.gqlService.gql({
query: getUserSettingsQuery,
});
return result.currentUser?.settings;
}
async updateUserSettings(settings: UpdateUserSettingsInput) {
await this.gqlService.gql({
query: updateUserSettingsMutation,
variables: {
input: settings,
},
});
}
}
@@ -4,6 +4,7 @@ import type { WorkspaceMetadata } from '../workspace';
export type SettingTab =
| 'shortcuts'
| 'notifications'
| 'appearance'
| 'about'
| 'plans'