diff --git a/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts b/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts index d39c798de3c1a306f8b69596cff455f17c7b1a22..b2ee6a3029bab83243bbac387309009210e382cd 100644 --- a/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts +++ b/src/app/components/shared/_dialogs/create-comment/create-comment.component.ts @@ -1,5 +1,5 @@ import { Component, Inject, OnDestroy, OnInit, ViewChild } from '@angular/core'; -import { Comment } from '../../../../models/comment'; +import { Comment, Language as CommentLanguage } from '../../../../models/comment'; import { NotificationService } from '../../../../services/util/notification.service'; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; import { TranslateService } from '@ngx-translate/core'; @@ -116,17 +116,12 @@ export class CreateCommentComponent implements OnInit, OnDestroy { } } - checkUTFEmoji(body: string): string { - const regex = /(?:\:.*?\:|[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/g; - - return body.replace(regex, ''); - } - openSpacyDialog(comment: Comment): void { CreateCommentKeywords.isSpellingAcceptable(this.languagetoolService, this.inputText, this.selectedLang) .subscribe((result) => { if (result.isAcceptable) { const commentLang = this.languagetoolService.mapLanguageToSpacyModel(result.result.language.code as Language); + comment.language = commentLang.toUpperCase() as CommentLanguage; const dialogRef = this.dialog.open(SpacyDialogComponent, { data: { comment, @@ -140,6 +135,7 @@ export class CreateCommentComponent implements OnInit, OnDestroy { } }); } else { + comment.language = CommentLanguage.auto; this.dialogRef.close(comment); } this.isSendingToSpacy = false; diff --git a/src/app/components/shared/_dialogs/worker-dialog/worker-dialog-task.ts b/src/app/components/shared/_dialogs/worker-dialog/worker-dialog-task.ts index a95509994bb41363ebfd56c16a1f2fa8d160c622..5bfdb4b459ff80efb336bd8635a6daed705b248d 100644 --- a/src/app/components/shared/_dialogs/worker-dialog/worker-dialog-task.ts +++ b/src/app/components/shared/_dialogs/worker-dialog/worker-dialog-task.ts @@ -51,7 +51,6 @@ export class WorkerDialogTask { } return; } - const fallbackmodel = (localStorage.getItem('currentLang') || 'de') as Model; const currentComment = this._comments[currentIndex]; CreateCommentKeywords.isSpellingAcceptable(this.languagetoolService, currentComment.body) .subscribe(result => { @@ -60,9 +59,15 @@ export class WorkerDialogTask { this.callSpacy(currentIndex + concurrentCallsPerTask); return; } - const model = this.languagetoolService - .mapLanguageToSpacyModel(result.result.language.detectedLanguage.code as Language); - this.spacyService.getKeywords(result.text, model === 'auto' ? fallbackmodel : model) + const commentModel = currentComment.language.toLowerCase(); + const model = commentModel !== 'auto' ? commentModel.toLowerCase() as Model : + this.languagetoolService.mapLanguageToSpacyModel(result.result.language.detectedLanguage.code as Language); + if (model === 'auto') { + this.statistics.badSpelled++; + this.callSpacy(currentIndex + concurrentCallsPerTask); + return; + } + this.spacyService.getKeywords(result.text, model) .subscribe(newKeywords => { const changes = new TSMap<string, string>(); changes.set('keywordsFromSpacy', JSON.stringify(newKeywords)); @@ -74,19 +79,16 @@ export class WorkerDialogTask { if (patchError instanceof HttpErrorResponse && patchError.status === 403) { this.error = 'forbidden'; } - console.log(patchError); }, () => { this.callSpacy(currentIndex + concurrentCallsPerTask); }); }, - keywordError => { + __ => { this.statistics.failed++; - console.log(keywordError); this.callSpacy(currentIndex + concurrentCallsPerTask); }); - }, error => { + }, _ => { this.statistics.failed++; - console.log(error); this.callSpacy(currentIndex + concurrentCallsPerTask); }); } diff --git a/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.html b/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.html index c79c3e2823960818fdf21898ae076a1f2ad97e60..77632d2beca37497f11686c5500481ebd61944b5 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.html +++ b/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.html @@ -42,7 +42,7 @@ </p> </span> </div> - <div class="replacementContainer" *ngIf="checkLanguage && user && user.role >= 1"> + <div class="replacementContainer" *ngIf="user && user.role >= 1"> <mat-form-field> <mat-label>{{'tag-cloud-popup.tag-correction-placeholder' | translate}}</mat-label> <input type="text" diff --git a/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts b/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts index 0c25bfda2a286c6c3f77110629964be649708243..367525de538c9961dc475a079ca5183d1c4cc9e5 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud-pop-up/tag-cloud-pop-up.component.ts @@ -30,7 +30,6 @@ export class TagCloudPopUpComponent implements OnInit, AfterViewInit { user: User; selectedLang: Language = 'en-US'; spellingData: string[] = []; - checkLanguage = false; private _popupHoverTimer: number; private _popupCloseTimer: number; private _hasLeft = true; @@ -77,24 +76,21 @@ export class TagCloudPopUpComponent implements OnInit, AfterViewInit { this.close(); } - enter(elem: HTMLElement, tag: string, tagData: TagCloudDataTagEntry, hoverDelayInMs: number, checkLanguage: boolean): void { - this.checkLanguage = checkLanguage; - if (checkLanguage) { - this.spellingData = []; - this.languagetoolService.checkSpellings(tag, 'auto').subscribe(correction => { - const langKey = correction.language.code.split('-')[0].toUpperCase(); - if (['DE', 'FR', 'EN'].indexOf(langKey) < 0) { - return; - } - for (const match of correction.matches) { - if (match.replacements != null && match.replacements.length > 0) { - for (const replacement of match.replacements) { - this.spellingData.push(replacement.value); - } + enter(elem: HTMLElement, tag: string, tagData: TagCloudDataTagEntry, hoverDelayInMs: number): void { + this.spellingData = []; + this.languagetoolService.checkSpellings(tag, 'auto').subscribe(correction => { + const langKey = correction.language.code.split('-')[0].toUpperCase(); + if (['DE', 'FR', 'EN'].indexOf(langKey) < 0) { + return; + } + for (const match of correction.matches) { + if (match.replacements != null && match.replacements.length > 0) { + for (const replacement of match.replacements) { + this.spellingData.push(replacement.value); } } - }); - } + } + }); clearTimeout(this._popupCloseTimer); clearTimeout(this._popupHoverTimer); this._hasLeft = true; diff --git a/src/app/components/shared/tag-cloud/tag-cloud.component.ts b/src/app/components/shared/tag-cloud/tag-cloud.component.ts index 0bf7233270fd5e425f643ab62bb12ce414463bdd..b2031204cd156199ad540b9f53b2022a213db794 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.component.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud.component.ts @@ -136,7 +136,6 @@ const getDefaultCloudParameters = (): CloudParameters => { hoverDelay: 0.4, delayWord: 0, randomAngles: true, - checkSpelling: true, sortAlphabetically: false, textTransform: CloudTextStyle.normal, cloudWeightSettings: weightSettings @@ -439,8 +438,7 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit, A }); elem.addEventListener('mouseenter', () => { this.popup.enter(elem, dataElement.text, dataElement.tagData, - (this._currentSettings.hoverTime + this._currentSettings.hoverDelay) * 1_000, - this._currentSettings.checkSpelling); + (this._currentSettings.hoverTime + this._currentSettings.hoverDelay) * 1_000); }); }); } diff --git a/src/app/components/shared/tag-cloud/tag-cloud.interface.ts b/src/app/components/shared/tag-cloud/tag-cloud.interface.ts index b6f0edf187bf9b80fc536327d88e54c876e8b7c5..240eb3b0b6eade4a3b802b0b482c091fec322e10 100644 --- a/src/app/components/shared/tag-cloud/tag-cloud.interface.ts +++ b/src/app/components/shared/tag-cloud/tag-cloud.interface.ts @@ -94,10 +94,6 @@ export interface CloudParameters { * Sorts the cloud alphabetical. */ sortAlphabetically: boolean; - /** - * Checks if the word is spelled correctly, if not, do not display it. - */ - checkSpelling: boolean; /** * Custom CSS text transform setting */ diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index 31f2711c1bb7d74934ca8e55802fd4aee2fdca20..4c878cc7831a9585068f9139da5d755d5659cdc9 100644 --- a/src/app/models/comment.ts +++ b/src/app/models/comment.ts @@ -1,6 +1,16 @@ -import { dashCaseToCamelCase } from '@angular/compiler/src/util'; import { CorrectWrong } from './correct-wrong.enum'; +export enum Language { + de = 'DE', + en = 'EN', + fr = 'FR', + es = 'ES', + it = 'IT', + nl = 'NL', + pt = 'PT', + auto = 'AUTO' +} + export class Comment { id: string; roomId: string; @@ -24,6 +34,7 @@ export class Comment { keywordsFromSpacy: string[]; upvotes: number; downvotes: number; + language: Language; constructor(roomId: string = '', creatorId: string = '', @@ -43,7 +54,8 @@ export class Comment { keywordsFromQuestioner: string[] = [], keywordsFromSpacy: string[] = [], upvotes = 0, - downvotes = 0) { + downvotes = 0, + language = Language.auto) { this.id = ''; this.roomId = roomId; this.creatorId = creatorId; @@ -65,5 +77,6 @@ export class Comment { this.keywordsFromSpacy = keywordsFromSpacy; this.upvotes = upvotes; this.downvotes = downvotes; + this.language = language; } } diff --git a/src/app/models/room.ts b/src/app/models/room.ts index d75c5ef3fefd803cbb4221df657f11634f9df922..9dfa28df8c808c597d74cc3db5eb19e0477221d1 100644 --- a/src/app/models/room.ts +++ b/src/app/models/room.ts @@ -1,8 +1,9 @@ export enum ProfanityFilterType { - all = 0, - languageSpecific, - partialWords, - none + all = 'ALL', + languageSpecific = 'LANGUAGE_SPECIFIC', + partialWords = 'PARTIAL_WORDS', + none = 'NONE', + deactivated = 'DEACTIVATED' } export class Room { diff --git a/src/app/services/http/room.service.ts b/src/app/services/http/room.service.ts index cce50ae4131be0d791fca18752a5e478aa2b9712..a622cb867007c9102df6978ae5db3240c6ae4a3f 100644 --- a/src/app/services/http/room.service.ts +++ b/src/app/services/http/room.service.ts @@ -136,9 +136,8 @@ export class RoomService extends BaseHttpService { setRoomId(room: Room): void { // temp solution until the backend is updated - const filter = +localStorage.getItem('room-profanity-filter'); - const isInvalid = Number.isNaN(filter) || filter < ProfanityFilterType.all || filter > ProfanityFilterType.none; - room.profanityFilter = isInvalid ? ProfanityFilterType.languageSpecific : filter; + const filter = localStorage.getItem('room-profanity-filter'); + room.profanityFilter = filter as ProfanityFilterType; localStorage.setItem('roomId', room.id); } } diff --git a/src/app/services/util/room-data.service.ts b/src/app/services/util/room-data.service.ts index ed5ffe832dacc18f8852971a29f5d961bc4af17b..665d292c120a63886cf5e7fc132ddde48f101dd8 100644 --- a/src/app/services/util/room-data.service.ts +++ b/src/app/services/util/room-data.service.ts @@ -216,19 +216,23 @@ export class RoomDataService { c.tag = payload.tag; c.creatorId = payload.creatorId; c.userNumber = this.commentService.hashCode(c.creatorId); + c.keywordsFromQuestioner = JSON.parse(payload.keywordsFromQuestioner); + this._fastCommentAccess[c.id] = c; + this._currentComments.push(c); this.triggerUpdate(UpdateType.commentStream, { type: 'CommentCreated', finished: false, comment: c }); this.commentService.getComment(c.id).subscribe(comment => { - this._fastCommentAccess[comment.id] = comment; - this._currentComments.push(comment); - this.setCommentBodies(comment); + for (const key of Object.keys(comment)) { + c[key] = comment[key]; + } + this.setCommentBodies(c); this.triggerUpdate(UpdateType.commentStream, { type: 'CommentCreated', finished: true, - comment + comment: c }); }); }