diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.ts b/src/app/components/creator/room-creator-page/room-creator-page.component.ts index 3b8b21ee6320534ed352cb76e572b084a1269529..3ef8a36d9bb53d069b3333c01ac68180a3187759 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.ts +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.ts @@ -21,6 +21,7 @@ import { LiveAnnouncer } from '@angular/cdk/a11y'; import { EventService } from '../../../services/util/event.service'; import { KeyboardUtils } from '../../../utils/keyboard'; import { KeyboardKey } from '../../../utils/keyboard/keys'; +import { TitleService } from '../../../services/util/title.service'; @Component({ selector: 'app-room-creator-page', @@ -49,8 +50,10 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni protected commentService: CommentService, private liveAnnouncer: LiveAnnouncer, private _r: Renderer2, - public eventService: EventService) { + public eventService: EventService, + public titleService: TitleService) { super(roomService, route, location, wsCommentService, commentService, eventService); + this.commentCounterEmit.subscribe(e => this.titleService.attachTitle('(' + e + ')')); langService.langEmitter.subscribe(lang => translateService.use(lang)); } diff --git a/src/app/components/shared/room-page/room-page.component.ts b/src/app/components/shared/room-page/room-page.component.ts index 08badadf7250b24100d3003ad1608eadced55b8e..d61ddc13fac550eec84f973646e881f61724d842 100644 --- a/src/app/components/shared/room-page/room-page.component.ts +++ b/src/app/components/shared/room-page/room-page.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Component, OnInit, OnDestroy, EventEmitter } from '@angular/core'; import { Room } from '../../../models/room'; import { User } from '../../../models/user'; import { RoomService } from '../../../services/http/room.service'; @@ -23,6 +23,7 @@ export class RoomPageComponent implements OnInit, OnDestroy { protected sub: Subscription; protected commentWatch: Observable<IMessage>; protected listenerFn: () => void; + public commentCounterEmit: EventEmitter<number> = new EventEmitter<number>(); constructor(protected roomService: RoomService, protected route: ActivatedRoute, @@ -64,16 +65,16 @@ export class RoomPageComponent implements OnInit, OnDestroy { localStorage.setItem('moderationEnabled', String(this.moderationEnabled)); this.commentService.countByRoomId(this.room.id, true) .subscribe(commentCounter => { - this.commentCounter = commentCounter; + this.setCommentCounter(commentCounter); }); this.commentWatch = this.wsCommentService.getCommentStream(this.room.id); this.sub = this.commentWatch.subscribe((message: Message) => { const msg = JSON.parse(message.body); const payload = msg.payload; if (msg.type === 'CommentCreated') { - this.commentCounter = this.commentCounter + 1; + this.setCommentCounter(this.commentCounter + 1); } else if (msg.type === 'CommentDeleted') { - this.commentCounter = this.commentCounter - 1; + this.setCommentCounter(this.commentCounter - 1); } }); this.postRoomLoadHook(); @@ -81,6 +82,11 @@ export class RoomPageComponent implements OnInit, OnDestroy { }); } + setCommentCounter(commentCounter: number) { + this.commentCounter = commentCounter; + this.commentCounterEmit.emit(this.commentCounter); + } + delete(room: Room): void { this.roomService.deleteRoom(room.id).subscribe(); this.location.back();