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 02c0cfc88b1b56d1c18dbb66ac6d743de6ae3b57..cb020d5fadb3109d406f6c436e7ba13c670cff65 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 @@ -21,7 +21,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { public considerVotes: boolean; public profanityFilter: boolean; public blacklistIsActive: boolean; - blacklist: string[]; + blacklist: string[] = []; blacklistSubscription = undefined; keywordOrFulltextENUM = KeywordOrFulltext; newKeyword = undefined; @@ -109,7 +109,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { constructor( @Inject(MAT_DIALOG_DATA) public data: Data, - public cloudDialogRef: MatDialogRef<TagCloudComponent>, + public cloudDialogRef: MatDialogRef<TopicCloudAdministrationComponent>, public confirmDialog: MatDialog, private notificationService: NotificationService, private translateService: TranslateService, @@ -139,7 +139,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { setAdminData(){ this.topicCloudAdminData = { - blacklist: this.topicCloudAdminService.getBlacklistWords(this.profanityFilter, this.blacklistIsActive), + blacklist: [], germanWantedLabels: this.wantedLabels['de'], englischWantedLabels: this.wantedLabels['en'], considerVotes: this.considerVotes, @@ -151,7 +151,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { } setDefaultAdminData() { - this.topicCloudAdminData = this.topicCloudAdminService.getAdminData; + this.topicCloudAdminData = this.topicCloudAdminService.getDefaultAdminData; if (this.topicCloudAdminData) { this.considerVotes = this.topicCloudAdminData.considerVotes; this.profanityFilter = this.topicCloudAdminData.profanityFilter; @@ -167,7 +167,7 @@ export class TopicCloudAdministrationComponent implements OnInit, OnDestroy { } getProfanityList() { - return this.topicCloudAdminService.getProfanityList(); + return this.topicCloudAdminService.getCustomProfanityList(); } sortQuestions(sortMode?: string) { diff --git a/src/app/services/util/topic-cloud-admin.service.ts b/src/app/services/util/topic-cloud-admin.service.ts index 4358e3ab82fec85bd1343e9d0130f7c89fc578b7..a94abae2409a6c40893a2ba01351beeb5a83c0a3 100644 --- a/src/app/services/util/topic-cloud-admin.service.ts +++ b/src/app/services/util/topic-cloud-admin.service.ts @@ -11,15 +11,16 @@ import { Observable, Subject } from 'rxjs'; providedIn: 'root', }) export class TopicCloudAdminService { + private adminData: Subject<TopicCloudAdminData>; private blacklist: Subject<string[]>; private profanityWords = []; - // private blacklist = []; // should be stored in backend private readonly profanityKey = 'custom-Profanity-List'; private readonly adminKey = 'Topic-Cloud-Admin-Data'; constructor(private roomService: RoomService, private translateService: TranslateService, private notificationService: NotificationService) { this.blacklist = new Subject<string[]>(); + this.adminData = new Subject<TopicCloudAdminData>(); /* put all arrays of languages together */ this.profanityWords = BadWords['en'] .concat(BadWords['de']) @@ -29,23 +30,15 @@ export class TopicCloudAdminService { .concat(BadWords['tr']); } - getBlacklistWords(profanityFilter: boolean, blacklistFilter: boolean) { - let words = []; - if (profanityFilter) { - // 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); - // } - return words; + get getAdminData(): Observable<TopicCloudAdminData>{ + return this.adminData.asObservable(); } - get getAdminData(): TopicCloudAdminData { + get getDefaultAdminData(): TopicCloudAdminData { let data = JSON.parse(localStorage.getItem(this.adminKey)); if (!data) { data = { - blacklist: this.profanityWords, + blacklist: [], wantedLabels: [], considerVotes: false, profanityFilter: true, @@ -56,8 +49,12 @@ export class TopicCloudAdminService { return data; } - setAdminData(adminData: TopicCloudAdminData) { - localStorage.setItem(this.adminKey, JSON.stringify(adminData)); + setAdminData(_adminData: TopicCloudAdminData) { + localStorage.setItem(this.adminKey, JSON.stringify(_adminData)); + this.getBlacklist().subscribe(list => { + _adminData.blacklist = this.getCustomProfanityList().concat(list); + this.adminData.next(_adminData); + }); } getBlacklist(): Observable<string[]>{ @@ -70,7 +67,7 @@ export class TopicCloudAdminService { filterProfanityWords(str: string): string { let questionWithProfanity = str; - this.profanityWords.concat(this.getProfanityList()).map((word) => { + this.profanityWords.concat(this.getCustomProfanityList()).map((word) => { questionWithProfanity = questionWithProfanity .toLowerCase() .includes(word.toLowerCase()) @@ -84,14 +81,14 @@ export class TopicCloudAdminService { return questionWithProfanity; } - getProfanityList(): string[] { + getCustomProfanityList(): string[] { const list = localStorage.getItem(this.profanityKey); return list ? list.split(',') : []; } addToProfanityList(word: string) { if (word !== undefined) { - const newList = this.getProfanityList(); + const newList = this.getCustomProfanityList(); if (newList.includes(word)) { return; } @@ -101,7 +98,7 @@ export class TopicCloudAdminService { } removeFromProfanityList(profanityWord: string) { - const list = this.getProfanityList(); + const list = this.getCustomProfanityList(); list.map(word => { if (word === profanityWord) { list.splice(list.indexOf(word, 0), 1);