From f12a685e8a6d9ac5cf71433e331c934f0979db47 Mon Sep 17 00:00:00 2001
From: mohammad <mohammad.alayoub@mni.thm.de>
Date: Tue, 1 Jun 2021 20:22:57 +0200
Subject: [PATCH] updated the methods remove- and addwordtobacklist

---
 .../topic-cloud-administration.component.ts   | 15 +++++++-------
 .../util/topic-cloud-admin.service.ts         | 20 ++++++++++++-------
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.ts b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.ts
index 202337fd0..0de00f7c5 100644
--- a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.ts
+++ b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.ts
@@ -123,15 +123,15 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy {
     }
 
   ngOnInit(): void {
-    this.isCreatorOrMod = (this.data.user.role !== UserRole.PARTICIPANT);
+    this.isCreatorOrMod = this.data ? (this.data.user.role !== UserRole.PARTICIPANT) : true;
     this.fillListOfLabels();
     this.translateService.use(localStorage.getItem('currentLang'));
     this.checkIfThereAreQuestions();
     this.sortQuestions();
-    this.roomService.getRoom(localStorage.getItem('roomId')).subscribe(room => {
-      this.topicCloudAdminService.setBlacklist(room.blacklist);
-      this.setDefaultAdminData();
-    });
+    // this.roomService.getRoom(localStorage.getItem('roomId')).subscribe(room => {
+    //   this.topicCloudAdminService.setBlacklist(room.blacklist);
+    //   this.setDefaultAdminData();
+    // });
   }
 
   ngOnDestroy(){
@@ -172,7 +172,8 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy {
   }
 
   getBlacklist() {
-    return this.topicCloudAdminService.getBlacklist();
+    return [];
+    // return this.topicCloudAdminService.getBlacklist();
   }
 
   sortQuestions(sortMode?: string) {
@@ -309,7 +310,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy {
   }
 
   addBlacklistWord() {
-    this.topicCloudAdminService.addToBlacklistWordList(this.newBlacklistWord);
+    this.topicCloudAdminService.addWordToBlacklist(this.newBlacklistWord);
     this.newBlacklistWord = undefined;
     if (this.searchMode){
       this.searchKeyword();
diff --git a/src/app/services/util/topic-cloud-admin.service.ts b/src/app/services/util/topic-cloud-admin.service.ts
index 90942eabe..2b704ae55 100644
--- a/src/app/services/util/topic-cloud-admin.service.ts
+++ b/src/app/services/util/topic-cloud-admin.service.ts
@@ -35,9 +35,9 @@ export class TopicCloudAdminService {
       // TODO: send only words that are contained in keywords
       words = words.concat(this.profanityWords).concat(this.getProfanityList());
     }
-    if (blacklistFilter && this.blacklist.length > 0) {
-      words = words.concat(this.blacklist);
-    }
+    // if (blacklistFilter && this.blacklist.length > 0) {
+    //   words = words.concat(this.blacklist);
+    // }
     return words;
   }
 
@@ -107,13 +107,15 @@ export class TopicCloudAdminService {
   }
 
   getRoom(): Observable<Room> {
-    return this.roomService.getRoom(localStorage.getItem('RoomId'));
+    return this.roomService.getRoom(localStorage.getItem('roomId'));
   }
 
   addWordToBlacklist(word: string) {
     if (word !== undefined) {
       this.getRoom().subscribe(room => {
-        room.blacklist = JSON.parse(room.blacklist).push(word);
+        const newlist = room.blacklist.length > 0 ? JSON.parse(room.blacklist) : [];
+        newlist.push(word);
+        room.blacklist = JSON.stringify(newlist);
         this.updateRoom(room);
       });
     }
@@ -122,8 +124,12 @@ export class TopicCloudAdminService {
   removeWordFromBlacklist(word: string) {
     if (word !== undefined) {
       this.getRoom().subscribe(room => {
-        room.blacklist = JSON.parse(room.blacklist).splice(room.blacklist.indexOf(word, 1));;
-        this.updateRoom(room);
+        if (room.blacklist.length > 0){
+          const newlist = JSON.parse(room.blacklist);
+          newlist.splice(newlist.indexOf(word, 0), 1);
+          room.blacklist = JSON.stringify(newlist);
+          this.updateRoom(room);
+        }
       });
     }
   }
-- 
GitLab