diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts index d0ab2285274ce4ed753d2cf9a9cd601eb04306fa..145cdf8285dbf337633c40678eab38a46f6812d6 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts @@ -31,7 +31,7 @@ import { isDone, isPending, } from '@alfa-client/command-shared'; -import { NavigationService } from '@alfa-client/navigation-shared'; +import { NavigationFacade, NavigationService, RouteData } from '@alfa-client/navigation-shared'; import { createEmptyStateResource, createStateResource, @@ -42,14 +42,14 @@ import { StateResource, } from '@alfa-client/tech-shared'; import { SnackBarService } from '@alfa-client/ui'; -import { VorgangResource, VorgangService, VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; +import { getVorgangParam, VorgangResource, VorgangService, VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; import { inject, Injectable } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { Params } from '@angular/router'; import { hasLink, Resource } from '@ngxp/rest'; import { isNil, isNull } from 'lodash-es'; import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs'; -import { first, map, take, tap } from 'rxjs/operators'; +import { first, map, switchMap, take, tap } from 'rxjs/operators'; import { PostfachFacade } from './+state/postfach.facade'; import { PostfachMailLinkRel, PostfachMailListLinkRel } from './postfach.linkrel'; import { PostfachMessages } from './postfach.message'; @@ -74,6 +74,7 @@ export class PostfachService { private readonly dialog = inject(MatDialog); private readonly postfachFacade = inject(PostfachFacade); private readonly binaryFileService = inject(BinaryFileService); + private readonly navigationFacade = inject(NavigationFacade); private readonly isPollSendPostachMail: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false); postfachMailList$: BehaviorSubject<StateResource<PostfachMailListResource>> = new BehaviorSubject< @@ -216,14 +217,42 @@ export class PostfachService { }); } - _doResetHasNewPostfachNachrichten(): void { + navigateToPostfach(): void { + this._doResetHasNewPostfachNachrichten(true); + } + + _doResetHasNewPostfachNachrichten(navigate: boolean = false): void { if (hasLink(this.postfachMailList$.value.resource, PostfachMailListLinkRel.RESET_HAS_NEW_POSTFACH_NACHRICHT)) { - this.repository.resetHasNewPostfachNachrichten(this.postfachMailList$.value.resource).pipe(take(1)).subscribe(); + this.repository + .resetHasNewPostfachNachrichten(this.postfachMailList$.value.resource) + .pipe(take(1)) + .subscribe(() => { + if (navigate) this._navigateToPostfach(); + }); + } else { + if (navigate) this._navigateToPostfach(); } } + _navigateToPostfach(): void { + this.navigationFacade + .getCurrentRouteData() + .pipe(take(1)) + .subscribe((currenRoute: RouteData) => { + this.navigationService.navigateToPostfach(getVorgangParam(currenRoute)); + }); + } + public setHasNewPostfachNachrichten() { - this.repository.setHasNewPostfachNachrichten(this.postfachMailList$.value.resource).pipe(take(1)).subscribe(); + this.repository + .setHasNewPostfachNachrichten(this.postfachMailList$.value.resource) + .pipe( + switchMap(() => this.navigationFacade.getCurrentRouteData()), + take(1), + ) + .subscribe((currenRoute: RouteData) => { + this.navigationService.navigateToVorgang(getVorgangParam(currenRoute)); + }); } _pollSendPostfachMailCommand(command: StateResource<CommandResource>): StateResource<CommandResource> {