From 1fecc23d5f0cec15e1c7965540543b8285f6933f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Wed, 25 Sep 2019 14:13:22 +0200 Subject: [PATCH] Implement comment-stream-freeze functionality --- .../comment-list/comment-list.component.html | 4 +-- .../comment-list/comment-list.component.ts | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/app/components/shared/comment-list/comment-list.component.html b/src/app/components/shared/comment-list/comment-list.component.html index e5c4b4b84..20a284324 100644 --- a/src/app/components/shared/comment-list/comment-list.component.html +++ b/src/app/components/shared/comment-list/comment-list.component.html @@ -36,13 +36,13 @@ </button> <button id="pause-comments" mat-fab aria-labelledby="pause" class="actionButton" - *ngIf="!searchBox.value && !search && !freeze" (click)="freeze = true;" + *ngIf="!searchBox.value && !search && !freeze" (click)="pauseCommentStream()" matTooltip="{{ 'comment-list.pause-comments' | translate }}"> <mat-icon class="pauseIcon">pause_circle_filled</mat-icon> </button> <button id="play-comments" mat-fab aria-labelledby="play" class="actionButton" - *ngIf="!searchBox.value && !search && freeze" (click)="freeze = false;" + *ngIf="!searchBox.value && !search && freeze" (click)="playCommentStream()" matTooltip="{{ 'comment-list.play-comments' | translate }}"> <mat-icon class="playIcon">play_circle_filled</mat-icon> </button> diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index ec069c4a7..f87e4f2c9 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -17,6 +17,7 @@ import { NotificationService } from '../../../services/util/notification.service import { CorrectWrong } from '../../../models/correct-wrong.enum'; import { LiveAnnouncer } from '@angular/cdk/a11y'; import { EventService } from '../../../services/util/event.service'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-comment-list', @@ -54,6 +55,8 @@ export class CommentListComponent implements OnInit { moderationEnabled = false; thresholdEnabled = false; newestComment: string; + freeze = false; + commentStream: Subscription; constructor(private commentService: CommentService, private translateService: TranslateService, @@ -88,9 +91,7 @@ export class CommentListComponent implements OnInit { }); }); this.hideCommentsList = false; - this.wsCommentService.getCommentStream(this.roomId).subscribe((message: Message) => { - this.parseIncomingMessage(message); - }); + this.subscribeCommentStream(); this.translateService.use(localStorage.getItem('currentLang')); this.deviceType = localStorage.getItem('deviceType'); if (this.userRole === 0) { @@ -311,6 +312,26 @@ export class CommentListComponent implements OnInit { this.currentSort = type; } + pauseCommentStream() { + this.freeze = true; + this.commentStream.unsubscribe(); + } + + playCommentStream() { + this.freeze = false; + this.commentService.getAckComments(this.roomId) + .subscribe(comments => { + this.comments = comments; + this.getComments(); + }); + this.subscribeCommentStream(); + } + + subscribeCommentStream() { + this.commentStream = this.wsCommentService.getCommentStream(this.roomId).subscribe((message: Message) => { + this.parseIncomingMessage(message); + }); + } /** * Announces a new comment receive. -- GitLab