RED-4162: Refresh notifications after preferences update
This commit is contained in:
parent
c333a55e8d
commit
7c652f6b87
@ -1,13 +1,18 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { GenericService } from '@iqser/common-ui';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { Observable, of, switchMap } from 'rxjs';
|
||||
import { UserService } from '@services/user.service';
|
||||
import { EmailNotificationScheduleTypes, INotificationPreferences } from '@red/domain';
|
||||
import { EmailNotificationScheduleTypes, INotificationPreferences, Notification } from '@red/domain';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { NotificationsService } from '@services/notifications.service';
|
||||
|
||||
@Injectable()
|
||||
export class NotificationPreferencesService extends GenericService<INotificationPreferences> {
|
||||
constructor(protected readonly _injector: Injector, private readonly _userService: UserService) {
|
||||
constructor(
|
||||
protected readonly _injector: Injector,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _notificationsService: NotificationsService,
|
||||
) {
|
||||
super(_injector, 'notification-preferences');
|
||||
}
|
||||
|
||||
@ -25,7 +30,7 @@ export class NotificationPreferencesService extends GenericService<INotification
|
||||
return super.get<INotificationPreferences>().pipe(catchError(() => of(this._defaultPreferences)));
|
||||
}
|
||||
|
||||
update(notificationPreferences: INotificationPreferences): Observable<void> {
|
||||
return super._post(notificationPreferences);
|
||||
update(notificationPreferences: INotificationPreferences): Observable<Notification[]> {
|
||||
return super._post(notificationPreferences).pipe(switchMap(() => this._notificationsService.loadAll()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,10 +47,10 @@ export class NotificationsService extends EntitiesService<Notification, INotific
|
||||
queryParam = { key: 'setRead', value: setRead };
|
||||
}
|
||||
|
||||
return this._post(body, `${this._defaultModelPath}/toggle-read`, [queryParam]).pipe(switchMap(() => this.#loadAll()));
|
||||
return this._post(body, `${this._defaultModelPath}/toggle-read`, [queryParam]).pipe(switchMap(() => this.loadAll()));
|
||||
}
|
||||
|
||||
#loadAll(includeSeen = INCLUDE_SEEN): Observable<Notification[]> {
|
||||
loadAll(includeSeen = INCLUDE_SEEN): Observable<Notification[]> {
|
||||
const queryParam: QueryParam = { key: 'includeSeen', value: includeSeen };
|
||||
|
||||
return this.getAll<{ notifications: Notification[] }>(this._defaultModelPath, [queryParam]).pipe(
|
||||
@ -61,7 +61,7 @@ export class NotificationsService extends EntitiesService<Notification, INotific
|
||||
}
|
||||
|
||||
#loadNotificationsIfChanged(): Observable<Notification[]> {
|
||||
return this.hasChanges$().pipe(switchMap(changed => iif(() => changed, this.#loadAll(), EMPTY)));
|
||||
return this.hasChanges$().pipe(switchMap(changed => iif(() => changed, this.loadAll(), EMPTY)));
|
||||
}
|
||||
|
||||
private _new(notification: INotification) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user