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 48536b11ee28b95942237003f24234d365f57abf..62f743558469ad2708c95ec0f60e6a66fe22a564 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 @@ -78,7 +78,7 @@ export class TopicCloudAdministrationComponent implements OnInit { questions: [ 'Das ist eine Testfrage fuer den Profanity Filter, du Arschloch', 'Fuck you!', - 'fuck Fuck ficken cunt', + 'fuck Fuck hiii cunt', 'fuck' ] }, @@ -228,7 +228,6 @@ export class TopicCloudAdministrationComponent implements OnInit { } return undefined; } - } interface Keyword { 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 874dac5e41a606e757060c4cbb6816fc5e8de7da..0994d89a2de25bf1d851bfd5a377d455f13feb7e 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 @@ -14,27 +14,42 @@ export class TopicDialogCommentComponent implements OnInit { @Input() isCollapsed = false; @Input() profanityFilter = true; public badWords = []; + questionWithProfinity: string = undefined; public shortQuestion: string; constructor() { } - get partsOfQuestion() { - // return this.question.slice(0,this.isCollapsed? this.question.length: this.maxShowedCharachters).split(new RegExp(this.keyword,'i')); - - const q = this.question.slice(0,this.isCollapsed? this.question.length: this.maxShowedCharachters); - // let q2 = q.split(new RegExp('(' + this.keyword + ')', 'i')); + get partsOfQuestion() { + const q = this.profanityFilter ? this.questionWithProfinity.slice(0,this.isCollapsed? this.question.length: this.maxShowedCharachters) : + this.question.slice(0,this.isCollapsed? this.question.length: this.maxShowedCharachters); const q2 = q.split(' '); return q2; } ngOnInit(): void { this.badWords = BadWordsList.array; + this.filterProfanityWords(); + } + + filterProfanityWords(){ + this.questionWithProfinity = this.question; + this.badWords.map(word =>{ + this.questionWithProfinity = this.questionWithProfinity.toLowerCase().includes(word) ? + this.replaceString(this.questionWithProfinity.toLowerCase(), word, this.generateXWord(word.length)) + : this.questionWithProfinity; + }); + } + + replaceString(str: string, search: string, replace: string){ + return str.split(search).join(replace); + } - // if (this.question.length > this.maxShowedCharachters) { - // this.shortQuestion = this.question.slice(0, this.maxShowedCharachters).concat('...'); - // } else { - // this.shortQuestion = this.question; - // } + generateXWord(count: number){ + let res = ''; + for (let i = 0; i < count; i++){ + res += '*'; + } + return res; } }