From 106ba524fbbc5c7861e1af2a5712a893b21faf66 Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Fri, 14 Feb 2020 15:57:59 +0900 Subject: [PATCH 1/3] bug fixed --- .../chat/create-chat.dialog.component.html | 3 +- .../chat/create-chat.dialog.component.ts | 48 ++++--------------- .../src/app/services/app.service.ts | 44 ++++++++++++++++- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.html index 39ccb89a..3cbfa33e 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/create-chat.dialog.component.html @@ -34,7 +34,8 @@ > {{ 'group.errors.bannedWords' - | translate: { bannedWords: bannedWords.join(',') } + | translate + : { bannedWords: appService.bannedGroupNames.join(',') } }} ( KEY_VER_INFO ); - - const banKeys: string[] = [ - 'group.nameFavorite', - 'group.nameMyDept', - 'group.nameDefault' - ]; - - const currentLang = this.translateService.currentLang; - const langs = ['ko', 'en']; - const translationObservables: Observable[] = []; - - langs.forEach(lang => { - translationObservables.push(this.translateService.getTranslation(lang)); - }); - - forkJoin(translationObservables) - .pipe(take(1)) - .subscribe( - translations => { - for (const translation of translations) { - banKeys.forEach(banKey => { - this.bannedWords.push( - this.translateParser.getValue(translation, banKey) - ); - }); - } - }, - error => {}, - () => { - this.translateService.use(currentLang); - } - ); } currentTabIndex: number; @@ -205,8 +176,6 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy { inputForm: FormGroup; - bannedWords: string[] = []; - groupTreeActivatedSubject = new BehaviorSubject(false); ngOnInit() { @@ -356,7 +325,10 @@ export class CreateChatDialogComponent implements OnInit, OnDestroy { return null; } const ban = - -1 < this.bannedWords.indexOf((control.value as string).trim()); + -1 < + this.appService.bannedGroupNames.indexOf( + (control.value as string).trim() + ); return ban ? { groupNameBanned: { value: control.value } } : null; }; } diff --git a/projects/ucap-webmessenger-app/src/app/services/app.service.ts b/projects/ucap-webmessenger-app/src/app/services/app.service.ts index 3b62e016..7097b7ae 100644 --- a/projects/ucap-webmessenger-app/src/app/services/app.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/app.service.ts @@ -7,20 +7,25 @@ import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native'; import { AppNativeService } from './native.service'; import { TranslateService as UCapTranslateService } from '@ucap-webmessenger/ui'; import { DateService as UCapDateService } from '@ucap-webmessenger/ui'; -import { TranslateService } from '@ngx-translate/core'; +import { TranslateService, TranslateParser } from '@ngx-translate/core'; import { EnviromentsService } from '@ucap-webmessenger/enviroments'; import { NGXLogger, NgxLoggerLevel } from 'ngx-logger'; import { environment } from '../../environments/environment'; +import { Observable, forkJoin } from 'rxjs'; +import { take } from 'rxjs/operators'; @Injectable() export class AppService { + bannedGroupNames: string[] = []; + constructor( private enviromentsService: EnviromentsService, private sessionStorageService: SessionStorageService, private appNotificationService: AppNotificationService, private appNativeService: AppNativeService, private translateService: TranslateService, + private translateParser: TranslateParser, private ucapTranslateService: UCapTranslateService, private ucapDateService: UCapDateService, @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService, @@ -42,6 +47,41 @@ export class AppService { } public postInit(): Promise { + const bannedGroupNamesPromise = new Promise((resolve, reject) => { + const banKeys: string[] = [ + 'group.nameFavorite', + 'group.nameMyDept', + 'group.nameDefault' + ]; + + const currentLang = this.translateService.currentLang; + const langs = ['ko', 'en']; + const translationObservables: Observable[] = []; + + langs.forEach(lang => { + translationObservables.push(this.translateService.getTranslation(lang)); + }); + + forkJoin(translationObservables) + .pipe(take(1)) + .subscribe( + translations => { + for (const translation of translations) { + banKeys.forEach(banKey => { + this.bannedGroupNames.push( + this.translateParser.getValue(translation, banKey) + ); + }); + } + }, + error => {}, + () => { + this.translateService.use(currentLang); + resolve(); + } + ); + }); + const initPromise = new Promise((resolve, reject) => { try { let deviceType: DeviceType; @@ -71,6 +111,6 @@ export class AppService { } }); - return Promise.all([initPromise]); + return Promise.all([initPromise, bannedGroupNamesPromise]); } } From 55170ae7029aee021f3f0578fa86d2c6e9fcb0a1 Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Fri, 14 Feb 2020 16:05:27 +0900 Subject: [PATCH 2/3] bug fixed --- .../src/app/layouts/messenger/components/messages.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts index 7170d259..6603e9c3 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts @@ -1146,7 +1146,7 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit { if (!!mediaFiles) { const fakeMedia = await this.commonApiService.checkInvalidMediaMimeForFileTalk( - fileUploadItems.map(fui => fui.file) + mediaFiles ); if (!fakeMedia.accept) { if (!!this.fileUploadQueue) { From 4debdf1ec969cf7ae409d8c3835182a394ef039f Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Fri, 14 Feb 2020 16:12:38 +0900 Subject: [PATCH 3/3] bug fixed --- .../src/lib/services/common-api.service.ts | 11 +++- .../components/messages.component.ts | 58 +++++++++---------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts b/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts index 380f8adf..36c85f80 100644 --- a/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts +++ b/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts @@ -228,9 +228,18 @@ export class CommonApiService { ): Promise<{ accept: boolean; rejected: string[] }> { return new Promise<{ accept: boolean; rejected: string[] }>( async (resolve, reject) => { + const mediaFiles = this.mediaFiles(files); + if (!mediaFiles) { + resolve({ + accept: true, + rejected: undefined + }); + return; + } + let accept = true; const rejected: string[] = []; - for (const file of files) { + for (const file of mediaFiles) { const info = await MimeUtil.getMimeFromBlob(file); // console.log('mime info', info); if ( diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts index 6603e9c3..df24f98a 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts @@ -1140,41 +1140,35 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit { return; } - const mediaFiles = this.commonApiService.mediaFiles( + const fakeMedia = await this.commonApiService.checkInvalidMediaMimeForFileTalk( fileUploadItems.map(fui => fui.file) ); - - if (!!mediaFiles) { - const fakeMedia = await this.commonApiService.checkInvalidMediaMimeForFileTalk( - mediaFiles - ); - if (!fakeMedia.accept) { - if (!!this.fileUploadQueue) { - this.fileUploadQueue.onUploadComplete(); - } - - this.snackBarService.openFromComponent< - AlertSnackbarComponent, - AlertSnackbarData - >(AlertSnackbarComponent, { - duration: 3000, - verticalPosition: 'bottom', - horizontalPosition: 'center', - data: { - html: this.translateService.instant( - 'common.file.errors.notAcceptableMime', - { - supporedType: - fakeMedia.rejected.length > 0 - ? fakeMedia.rejected.join(',') - : '' - } - ) - } - }); - - return; + if (!fakeMedia.accept) { + if (!!this.fileUploadQueue) { + this.fileUploadQueue.onUploadComplete(); } + + this.snackBarService.openFromComponent< + AlertSnackbarComponent, + AlertSnackbarData + >(AlertSnackbarComponent, { + duration: 3000, + verticalPosition: 'bottom', + horizontalPosition: 'center', + data: { + html: this.translateService.instant( + 'common.file.errors.notAcceptableMime', + { + supporedType: + fakeMedia.rejected.length > 0 + ? fakeMedia.rejected.join(',') + : '' + } + ) + } + }); + + return; } for (const fileUploadItem of fileUploadItems) {