diff --git a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html index 115c1b6aedd5f5cf2162917fe5f5d6f2b586992b..b2550e6e061734c8e9fa1edd569e14d46f7808d3 100644 --- a/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html +++ b/src/app/components/shared/_dialogs/topic-cloud-administration/topic-cloud-administration.component.html @@ -56,7 +56,7 @@ </button> <mat-list role="list" *ngIf="showProfanityList" class="margin-bottom"> - <mat-list-item class="color-on-surface" *ngFor="let word of getProfanityList()" role="listitem">{{word}} + <mat-list-item class="color-on-surface" *ngFor="let word of profanitywordlist" role="listitem">{{word}} <button style="margin-left: auto" mat-icon-button class="red" (click)="removeWordFromProfanityList(word)"> <mat-icon mat-list-icon style="margin-bottom: 6px;">delete</mat-icon> @@ -65,7 +65,7 @@ </mat-list> <div> - <button mat-raised-button *ngIf="getProfanityList().length > 0" class="primaryBackground" + <button mat-raised-button *ngIf="profanitywordlist.length > 0" class="primaryBackground" (click)="showProfanityList=!showProfanityList"> {{showProfanityList ? ('topic-cloud-dialog.hide-profanity-list' | translate) : ('topic-cloud-dialog.show-profanity-list' | translate)}} 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 8fd4c34e98c41d0e66029fa05780c22c82fdc9ff..b8eb3339a6e8c699d50534d7d465d980c28fb419 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 @@ -25,7 +25,9 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { public profanityFilter: boolean; public blacklistIsActive: boolean; blacklist: string[] = []; + profanitywordlist: string[] = []; blacklistSubscription = undefined; + profanitylistSubscription = undefined; keywordOrFulltextENUM = KeywordOrFulltext; newKeyword = undefined; edit = false; @@ -73,6 +75,10 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { this.deviceType = localStorage.getItem('deviceType'); this.wsCommentServiceService.getCommentStream(localStorage.getItem('roomId')).subscribe(_ => this.updateKeywords()); this.blacklistSubscription = this.topicCloudAdminService.getBlacklist().subscribe(list => this.blacklist = list); + this.profanitylistSubscription = this.topicCloudAdminService.getCustomProfanityList().subscribe(list => { + this.profanitywordlist = list; + this.updateKeywords(); + }); this.isCreatorOrMod = this.data.user.role !== UserRole.PARTICIPANT; this.translateService.use(localStorage.getItem('currentLang')); this.spacyLabels = spacyLabels; @@ -86,6 +92,9 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { if(this.blacklistSubscription !== undefined){ this.blacklistSubscription.unsubscribe(); } + if(this.profanitylistSubscription !== undefined){ + this.profanitylistSubscription.unsubscribe(); + } } updateKeywords(){ diff --git a/src/app/components/shared/dialog/topic-dialog-comment/topic-dialog-comment.component.ts b/src/app/components/shared/dialog/topic-dialog-comment/topic-dialog-comment.component.ts index 0fb96c843f3a1ee052908075b61e7c8de3cafe20..b18eb274e596198e1f1287034630db4da2e4e829 100644 --- a/src/app/components/shared/dialog/topic-dialog-comment/topic-dialog-comment.component.ts +++ b/src/app/components/shared/dialog/topic-dialog-comment/topic-dialog-comment.component.ts @@ -22,7 +22,7 @@ export class TopicDialogCommentComponent implements OnInit { public partsShort: string[]; public partsWithoutProfanityShort: string[]; - constructor(private topicCloudAdminService: TopicCloudAdminService) { } + constructor(private topicCloudAdminService: TopicCloudAdminService) {} get partsOfQuestion() { if (this.profanityFilter) { @@ -47,8 +47,8 @@ export class TopicDialogCommentComponent implements OnInit { ngOnInit(): void { this.questionWithoutProfanity = this.topicCloudAdminService.filterProfanityWords(this.question); this.partsWithoutProfanity = this.questionWithoutProfanity.split(new RegExp(this.keyword,'i')); + this.partsWithoutProfanityShort = this.shortQuestionParts(this.questionWithoutProfanity); this.parts = this.question.split(new RegExp(this.keyword,'i')); this.partsShort = this.shortQuestionParts(this.question); - this.partsWithoutProfanityShort = this.shortQuestionParts(this.questionWithoutProfanity); } } diff --git a/src/app/services/util/topic-cloud-admin.service.ts b/src/app/services/util/topic-cloud-admin.service.ts index 8b54e677e284bb4d9fa3e0d08ef3da12fcde7ce4..a0c2d6fa9937359d53b3adecff9949713119be37 100644 --- a/src/app/services/util/topic-cloud-admin.service.ts +++ b/src/app/services/util/topic-cloud-admin.service.ts @@ -15,6 +15,7 @@ export class TopicCloudAdminService { private adminData: Subject<TopicCloudAdminData>; private blacklist: Subject<string[]>; private profanityWords = []; + private customProfanityWords: Subject<string[]>; private readonly profanityKey = 'custom-Profanity-List'; private readonly adminKey = 'Topic-Cloud-Admin-Data'; constructor(private roomService: RoomService, @@ -22,6 +23,7 @@ export class TopicCloudAdminService { private notificationService: NotificationService) { this.blacklist = new Subject<string[]>(); this.adminData = new Subject<TopicCloudAdminData>(); + this.customProfanityWords = new Subject<string[]>(); /* put all arrays of languages together */ this.profanityWords = BadWords['en'] .concat(BadWords['de']) @@ -57,13 +59,17 @@ export class TopicCloudAdminService { localStorage.setItem(this.adminKey, JSON.stringify(_adminData)); this.getBlacklist().subscribe(list => { _adminData.blacklist = []; - if (_adminData.profanityFilter){ - _adminData.blacklist = this.getCustomProfanityList().concat(this.profanityWords); - } if (_adminData.blacklistIsActive){ _adminData.blacklist.concat(list); } - this.adminData.next(_adminData); + if (_adminData.profanityFilter){ + this.getCustomProfanityList().subscribe(plist => { + _adminData.blacklist = plist.concat(this.profanityWords); + this.adminData.next(_adminData); + }); + } else { + this.adminData.next(_adminData); + } }); } @@ -75,30 +81,32 @@ export class TopicCloudAdminService { return this.blacklist.asObservable(); } - getCustomProfanityList(): string[] { + getProfanityListFromStorage(){ const list = localStorage.getItem(this.profanityKey); - return list ? list.split(',') : []; + return list ? JSON.parse(list) : []; + } + + getCustomProfanityList(): Observable<string[]> { + this.customProfanityWords.next(this.getProfanityListFromStorage()); + return this.customProfanityWords.asObservable(); } addToProfanityList(word: string) { if (word !== undefined) { - const newList = this.getCustomProfanityList(); - if (newList.includes(word.toLowerCase().trim())) { - return; + const plist = this.getProfanityListFromStorage(); + if (!plist.includes(word.toLowerCase().trim())) { + plist.push(word.toLowerCase().trim()); + this.customProfanityWords.next(plist); + localStorage.setItem(this.profanityKey, JSON.stringify(plist)); } - newList.push(word.toLowerCase().trim()); - localStorage.setItem(this.profanityKey, newList.toString()); } } - removeFromProfanityList(profanityWord: string) { - const list = this.getCustomProfanityList(); - list.map(word => { - if (word === profanityWord) { - list.splice(list.indexOf(word, 0), 1); - } - }); - localStorage.setItem(this.profanityKey, list.toString()); + removeFromProfanityList(word: string) { + const plist = this.getProfanityListFromStorage(); + plist.splice(plist.indexOf(word, 0), 1); + this.customProfanityWords.next(plist); + localStorage.setItem(this.profanityKey, JSON.stringify(plist)); } removeProfanityList() { @@ -173,7 +181,7 @@ export class TopicCloudAdminService { filterProfanityWords(str: string): string { let questionWithProfanity = str; - this.profanityWords.concat(this.getCustomProfanityList()).map((word) => { + this.profanityWords.concat(this.getProfanityListFromStorage()).map((word) => { questionWithProfanity = questionWithProfanity .toLowerCase() .includes(word)