refreshing current user on WS connect

This commit is contained in:
Patrick Haßel 2024-10-24 15:54:17 +02:00
parent 7ff944dec4
commit aa126f7f45

View File

@ -7,6 +7,7 @@ import {UserPublic} from "./UserPublic";
import {Router} from "@angular/router"; import {Router} from "@angular/router";
import {BehaviorSubject, Subscription} from "rxjs"; import {BehaviorSubject, Subscription} from "rxjs";
import {AbstractSession} from "../Session/AbstractSession"; import {AbstractSession} from "../Session/AbstractSession";
import {StompService} from "@stomp/ng2-stompjs";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -22,8 +23,11 @@ export class UserService {
constructor( constructor(
protected readonly router: Router, protected readonly router: Router,
protected readonly api: ApiService, protected readonly api: ApiService,
protected readonly stompService: StompService,
) { ) {
this.refresh(); this.stompService.connected$.subscribe(() => {
this.refresh();
});
} }
getCommonByUuid(uuid: string, next: Next<UserCommon>): void { getCommonByUuid(uuid: string, next: Next<UserCommon>): void {
@ -38,7 +42,10 @@ export class UserService {
} }
changeName(name: string, next?: Next<UserPrivate>) { changeName(name: string, next?: Next<UserPrivate>) {
this.api.postSingle(['User', 'changeName'], name, UserPrivate.fromJson, next); this.api.postSingle(['User', 'changeName'], name, UserPrivate.fromJson, user => {
this.refresh();
next && next(user);
});
} }
goto(user: UserPublic) { goto(user: UserPublic) {