From b846dadb2a5e9b97af05c78c3a14ba1b60de05ac Mon Sep 17 00:00:00 2001
From: mohammad <mohammad.alayoub@mni.thm.de>
Date: Tue, 29 Jun 2021 13:42:12 +0200
Subject: [PATCH] Implement #163

---
 .../shared/comment/comment.component.ts       | 22 +++++++++++++++----
 src/app/services/util/room-data.service.ts    |  8 +++++++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts
index a471c154e..c675aabe3 100644
--- a/src/app/components/shared/comment/comment.component.ts
+++ b/src/app/components/shared/comment/comment.component.ts
@@ -44,6 +44,9 @@ export class CommentComponent implements OnInit, AfterViewInit {
   @Output() clickedOnTag = new EventEmitter<string>();
   @Output() clickedOnKeyword = new EventEmitter<string>();
   @Output() clickedUserNumber = new EventEmitter<number>();
+  @ViewChild('commentBody', { static: true })commentBody: RowComponent;
+  @ViewChild('commentBodyInner', { static: true })commentBodyInner: RowComponent;
+  @ViewChild('commentExpander', { static: true })commentExpander: RowComponent;
   isStudent = false;
   isCreator = false;
   isModerator = false;
@@ -54,12 +57,10 @@ export class CommentComponent implements OnInit, AfterViewInit {
   currentVote: string;
   slideAnimationState = 'hidden';
   roleString: string;
-  @ViewChild('commentBody', { static: true })commentBody: RowComponent;
-  @ViewChild('commentBodyInner', { static: true })commentBodyInner: RowComponent;
-  @ViewChild('commentExpander', { static: true })commentExpander: RowComponent;
   isExpanded = false;
   isExpandable = false;
-  selectedKeyword: string = '';
+  selectedKeyword = '';
+  filterProfanityForModerators = false;
 
   constructor(protected authenticationService: AuthenticationService,
     private route: ActivatedRoute,
@@ -104,6 +105,19 @@ export class CommentComponent implements OnInit, AfterViewInit {
     }
   }
 
+  changeProfanityShowForModerators(comment: Comment) {
+    let newBody: string;
+    if (this.filterProfanityForModerators) {
+      newBody = this.roomDataService.getFilteredBody(comment.id);
+    } else {
+      newBody = this.roomDataService.getUnFilteredBody(comment.id);
+    }
+    if (newBody) {
+      comment.body = newBody;
+    }
+    this.filterProfanityForModerators = !this.filterProfanityForModerators;
+  }
+
   ngAfterViewInit(): void {
     this.isExpandable = this.commentBody.getRenderedHeight() > CommentComponent.COMMENT_MAX_HEIGHT;
     if (!this.isExpandable) {
diff --git a/src/app/services/util/room-data.service.ts b/src/app/services/util/room-data.service.ts
index 498e8c262..5e0a3b462 100644
--- a/src/app/services/util/room-data.service.ts
+++ b/src/app/services/util/room-data.service.ts
@@ -157,6 +157,14 @@ export class RoomDataService {
     }
   }
 
+  getUnFilteredBody(id: string): string {
+    return this._savedCommentsBeforeFilter.get(id);
+  }
+
+  getFilteredBody(id: string): string {
+    return this._savedCommentsAfterFilter.get(id);
+  }
+
   private setCommentBody(comment: Comment) {
     this._savedCommentsBeforeFilter.set(comment.id, comment.body);
     this._savedCommentsAfterFilter.set(comment.id, this.filterCommentOfProfanity(this.room, comment));
-- 
GitLab