There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix(core): not revalidate notification count when logged out (#11617)
EYHN0f39ab4ea415
diff --git a/packages/frontend/core/src/modules/notification/index.ts b/packages/frontend/core/src/modules/notification/index.tsindex a1f5f97e34..f81d423a63 100644--- a/packages/frontend/core/src/modules/notification/index.ts+++ b/packages/frontend/core/src/modules/notification/index.ts@@ -6,7 +6,12 @@ export { NotificationType } from './stores/notification';import type { Framework } from '@toeverything/infra';-import { GraphQLService, ServerScope, ServerService } from '../cloud';+import {+ AuthService,+ GraphQLService,+ ServerScope,+ ServerService,+} from '../cloud';import { GlobalSessionState } from '../storage';import { NotificationCountService } from './services/count';import { NotificationListService } from './services/list';@@ -17,7 +22,7 @@ export function configureNotificationModule(framework: Framework) {framework.scope(ServerScope).service(NotificationService, [NotificationStore])- .service(NotificationCountService, [NotificationStore])+ .service(NotificationCountService, [NotificationStore, AuthService]).service(NotificationListService, [NotificationStore,NotificationCountService,diff --git a/packages/frontend/core/src/modules/notification/services/count.ts b/packages/frontend/core/src/modules/notification/services/count.tsindex 8c57aff083..1861f039ad 100644--- a/packages/frontend/core/src/modules/notification/services/count.ts+++ b/packages/frontend/core/src/modules/notification/services/count.ts@@ -12,17 +12,24 @@ import {} from '@toeverything/infra';import { EMPTY, mergeMap, switchMap, timer } from 'rxjs';+import { AccountChanged, type AuthService } from '../../cloud';import { ServerStarted } from '../../cloud/events/server-started';import { ApplicationFocused } from '../../lifecycle';import type { NotificationStore } from '../stores/notification';@OnEvent(ApplicationFocused, s => s.handleApplicationFocused)@OnEvent(ServerStarted, s => s.handleServerStarted)+@OnEvent(AccountChanged, s => s.handleAccountChanged)export class NotificationCountService extends Service {- constructor(private readonly store: NotificationStore) {+ constructor(+ private readonly store: NotificationStore,+ private readonly authService: AuthService+ ) {super();}+ loggedIn$ = this.authService.session.status$.map(v => v === 'authenticated');+readonly count$ = LiveData.from(this.store.watchNotificationCountCache(), 0);readonly isLoading$ = new LiveData(false);readonly error$ = new LiveData<any>(null);@@ -32,9 +39,12 @@ export class NotificationCountService extends Service {return timer(0, 30000); // revalidate every 30 seconds}),exhaustMapWithTrailing(() => {- return fromPromise(signal =>- this.store.getNotificationCount(signal)- ).pipe(+ return fromPromise(signal => {+ if (!this.loggedIn$.value) {+ return Promise.resolve(0);+ }+ return this.store.getNotificationCount(signal);+ }).pipe(mergeMap(result => {this.setCount(result ?? 0);return EMPTY;@@ -57,6 +67,10 @@ export class NotificationCountService extends Service {this.revalidate();}+ handleAccountChanged() {+ this.revalidate();+ }+setCount(count: number) {this.store.setNotificationCountCache(count);}