mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(core): not revalidate notification count when logged out (#11617)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user