diff --git a/electron-projects/ucap-webmessenger-electron/src/index.ts b/electron-projects/ucap-webmessenger-electron/src/index.ts index dcfc113a..313a4149 100644 --- a/electron-projects/ucap-webmessenger-electron/src/index.ts +++ b/electron-projects/ucap-webmessenger-electron/src/index.ts @@ -603,7 +603,10 @@ ipcMain.on( dialog .showSaveDialog({ defaultPath: args[0] }) .then(obj => { - event.returnValue = obj.filePath; + event.returnValue = { + canceled: obj.canceled, + filePath: obj.filePath + }; }) .catch(obj => { event.returnValue = undefined; diff --git a/projects/ucap-webmessenger-api-message/src/lib/apis/send.ts b/projects/ucap-webmessenger-api-message/src/lib/apis/send.ts index 39d9559f..0518b8b6 100644 --- a/projects/ucap-webmessenger-api-message/src/lib/apis/send.ts +++ b/projects/ucap-webmessenger-api-message/src/lib/apis/send.ts @@ -4,7 +4,8 @@ import { APIJsonEncoder, APIDecoder, APIFormDataEncoder, - ParameterUtil + ParameterUtil, + MessageStatusCode } from '@ucap-webmessenger/api'; import { DeviceType } from '@ucap-webmessenger/core'; import { MessageType } from '../types/message.type'; @@ -82,7 +83,7 @@ export const encodeSend: APIFormDataEncoder = ( export const decodeSend: APIDecoder = (res: any) => { return { - responseCode: res.responseCode, + responseCode: res.responseCode as MessageStatusCode, responseMsg: res.responseMsg } as SendResponse; }; diff --git a/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.ts b/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.ts index 7f0be966..f43d5bc2 100644 --- a/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.ts +++ b/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.ts @@ -168,7 +168,7 @@ export class MessageApiService { 'POST', this.urls.sendNewMessage, encodeSend(req), - { reportProgress: true, responseType: 'text' as 'json' } + { reportProgress: true } ); const progress = req.fileUploadItem.uploadStart(); @@ -196,7 +196,7 @@ export class MessageApiService { 'POST', this.urls.editReservationMessageEx, encodeEditReservation(req), - { reportProgress: true, responseType: 'text' as 'json' } + { reportProgress: true } ); const progress = req.fileUploadItem.uploadStart(); diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-nav.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-nav.component.ts index ff44f3f2..25f3c2e8 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-nav.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-nav.component.ts @@ -1,57 +1,20 @@ -import { UserSelectDialogType } from '../../../types/userselect.dialog.type'; import { Component, OnInit, - Output, - EventEmitter, - ViewChildren, - QueryList, - ElementRef, OnDestroy, - ViewChild } from '@angular/core'; import { NGXLogger } from 'ngx-logger'; -import { ucapAnimations, DialogService } from '@ucap-webmessenger/ui'; -import { - CreateChatDialogComponent, - CreateChatDialogData, - CreateChatDialogResult -} from '@app/layouts/messenger/dialogs/chat/create-chat.dialog.component'; -import { Subscription, Observable, merge } from 'rxjs'; +import { ucapAnimations } from '@ucap-webmessenger/ui'; +import { Subscription, Observable, } from 'rxjs'; import { Store, select } from '@ngrx/store'; import * as AppStore from '@app/store'; -import * as ChatStore from '@app/store/messenger/chat'; import * as MessageStore from '@app/store/messenger/message'; -import * as SyncStore from '@app/store/messenger/sync'; import * as SettingsStore from '@app/store/messenger/settings'; -import { UserInfo } from '@ucap-webmessenger/protocol-sync'; -import { - UserInfoSS, - UserInfoF, - UserInfoDN -} from '@ucap-webmessenger/protocol-query'; import { MatTabChangeEvent } from '@angular/material'; -import { LoginResponse } from '@ucap-webmessenger/protocol-authentication'; -import { OpenProfileOptions } from '@ucap-webmessenger/protocol-buddy'; -import { SessionStorageService } from '@ucap-webmessenger/web-storage'; -import { VersionInfo2Response } from '@ucap-webmessenger/api-public'; -import { MessageType } from '@ucap-webmessenger/api-message'; -import { tap } from 'rxjs/operators'; import { - MessageWriteDialogComponent, - MessageWriteDialogResult, - MessageWriteDialogData -} from '../dialogs/message/message-write.dialog.component'; -import { - EnvironmentsInfo, - KEY_ENVIRONMENTS_INFO, - KEY_VER_INFO, MainMenu } from '@app/types'; -import { MessageBoxComponent } from './left-sidenav/message.component'; -import { environment } from '../../../../environments/environment'; -import { TranslateService } from '@ngx-translate/core'; @Component({ selector: 'app-layout-messenger-left-nav', 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 adea76cd..f6e766fb 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 @@ -918,15 +918,19 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit { this.nativeService .selectSaveFilePath(value.fileInfo.fileName) .then(result => { - if (!!result && result.length > 0) { - this.saveFile(value, result); + if (!!result && result.filePath.length > 0) { + this.saveFile(value, result.filePath); } else { - this.snackBarService.open( - this.translateService.instant( - 'common.file.errors.failToSpecifyPath' - ), - this.translateService.instant('common.file.errors.label') - ); + if (!!result && result.canceled) { + // ignore.. + } else { + this.snackBarService.open( + this.translateService.instant( + 'common.file.errors.failToSpecifyPath' + ), + this.translateService.instant('common.file.errors.label') + ); + } } }) .catch(reason => { diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.ts index c388fa50..30642ab0 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/message/message-write.dialog.component.ts @@ -1,7 +1,13 @@ import { Component, OnInit, Inject, ViewChild } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; -import { DialogService, SnackBarService } from '@ucap-webmessenger/ui'; +import { + DialogService, + SnackBarService, + AlertDialogComponent, + AlertDialogResult, + AlertDialogData +} from '@ucap-webmessenger/ui'; import { DetailResponse, @@ -32,13 +38,14 @@ import { EnvironmentsInfo, KEY_VER_INFO } from '@app/types'; -import { take } from 'rxjs/operators'; +import { take, tap } from 'rxjs/operators'; import { UserInfoSS } from '@ucap-webmessenger/protocol-query'; import { TranslateService } from '@ngx-translate/core'; import { VersionInfo2Response } from '@ucap-webmessenger/api-public'; import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { environment } from '../../../../../environments/environment'; import { EmployeeType } from '@ucap-webmessenger/protocol-room'; +import { MessageStatusCode } from '@ucap-webmessenger/api'; export interface MessageWriteDialogData { loginRes: LoginResponse; @@ -155,23 +162,93 @@ export class MessageWriteDialogComponent implements OnInit { .pipe(take(1)) .subscribe( res => { - let msg = ''; - if (!!message.reservationTime) { - msg = this.translateService.instant( - 'message.results.successForReservation' - ); + if (!!res && res.responseCode === MessageStatusCode.Success) { + let msg = ''; + if (!!message.reservationTime) { + msg = this.translateService.instant( + 'message.results.successForReservation' + ); + } else { + msg = this.translateService.instant( + 'message.results.successForSending' + ); + } + + this.snackBarService.open(msg, '', { + duration: 3000, + verticalPosition: 'bottom' + }); + + this.dialogRef.close({ sendFlag: true, sendType: message.type }); } else { - msg = this.translateService.instant( - 'message.results.successForSending' - ); + let alertType = 'S'; + let errorMsg = + this.translateService.instant('message.errors.failToSending') + + `(${res.responseCode})`; + switch (res.responseCode) { + case MessageStatusCode.Fail_Msg_Reservation_Time_Null: + errorMsg = this.translateService.instant( + 'message.errors.failToReservationTimeEmpty' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_Msg_Title_length: + errorMsg = this.translateService.instant( + 'message.errors.failToTitleLength' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_Msg_Reservation_Time_Less: + case MessageStatusCode.Fail_Msg_Edit_Reservation_Time_Less: + errorMsg = this.translateService.instant( + 'message.errors.failToReservationTimeLess' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_Msg_Edit_Cancel_Reservation_Sended: + errorMsg = this.translateService.instant( + 'message.errors.failToReservationSended' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_File_Size: + errorMsg = this.translateService.instant( + 'message.errors.failToFileSize' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_File_Ext: + errorMsg = this.translateService.instant( + 'message.errors.failToFileExt' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_Cancelled_Msg: + errorMsg = this.translateService.instant( + 'message.errors.failToCancelled' + ); + alertType = 'A'; + break; + } + + if (alertType === 'S') { + this.snackBarService.open(errorMsg, '', { + duration: 3000, + verticalPosition: 'bottom' + }); + } else { + this.dialogService.open< + AlertDialogComponent, + AlertDialogData, + AlertDialogResult + >(AlertDialogComponent, { + data: { + title: this.translateService.instant('message.errors.label'), + message: errorMsg + } + }); + } } - - this.snackBarService.open(msg, '', { - duration: 3000, - verticalPosition: 'bottom' - }); - - this.dialogRef.close({ sendFlag: true, sendType: message.type }); }, error => { this.snackBarService.open( @@ -199,18 +276,88 @@ export class MessageWriteDialogComponent implements OnInit { .pipe(take(1)) .subscribe( res => { - this.snackBarService.open( - this.translateService.instant( - 'message.results.successForModifying' - ), - '', - { - duration: 3000, - verticalPosition: 'bottom' - } - ); + if (!!res && res.responseCode === MessageStatusCode.Success) { + this.snackBarService.open( + this.translateService.instant( + 'message.results.successForModifying' + ), + '', + { + duration: 3000, + verticalPosition: 'bottom' + } + ); - this.dialogRef.close({ sendFlag: true, sendType: message.type }); + this.dialogRef.close({ sendFlag: true, sendType: message.type }); + } else { + let alertType = 'S'; + let errorMsg = + this.translateService.instant('message.errors.failToSending') + + `(${res.responseCode})`; + switch (res.responseCode) { + case MessageStatusCode.Fail_Msg_Reservation_Time_Null: + errorMsg = this.translateService.instant( + 'message.errors.failToReservationTimeEmpty' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_Msg_Title_length: + errorMsg = this.translateService.instant( + 'message.errors.failToTitleLength' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_Msg_Reservation_Time_Less: + case MessageStatusCode.Fail_Msg_Edit_Reservation_Time_Less: + errorMsg = this.translateService.instant( + 'message.errors.failToReservationTimeLess' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_Msg_Edit_Cancel_Reservation_Sended: + errorMsg = this.translateService.instant( + 'message.errors.failToReservationSended' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_File_Size: + errorMsg = this.translateService.instant( + 'message.errors.failToFileSize' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_File_Ext: + errorMsg = this.translateService.instant( + 'message.errors.failToFileExt' + ); + alertType = 'A'; + break; + case MessageStatusCode.Fail_Cancelled_Msg: + errorMsg = this.translateService.instant( + 'message.errors.failToCancelled' + ); + alertType = 'A'; + break; + } + + if (alertType === 'S') { + this.snackBarService.open(errorMsg, '', { + duration: 3000, + verticalPosition: 'bottom' + }); + } else { + this.dialogService.open< + AlertDialogComponent, + AlertDialogData, + AlertDialogResult + >(AlertDialogComponent, { + data: { + title: this.translateService.instant('message.errors.label'), + message: errorMsg + } + }); + } + } }, error => { this.snackBarService.open( diff --git a/projects/ucap-webmessenger-app/src/app/layouts/native/components/top-bar.component.html b/projects/ucap-webmessenger-app/src/app/layouts/native/components/top-bar.component.html index 58772adf..66e5729a 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/native/components/top-bar.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/native/components/top-bar.component.html @@ -149,7 +149,10 @@ - + { - return new Promise((resolve, reject) => { - resolve(''); + selectSaveFilePath(defaultPath?: string): Promise<{ + canceled: boolean, + filePath: string + }> { + return new Promise<{ + canceled: boolean, + filePath: string + }>((resolve, reject) => { + resolve({ + canceled: false, + filePath: '' + }); }); } diff --git a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts index c54ae3ab..2b37b986 100644 --- a/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts +++ b/projects/ucap-webmessenger-native-electron/src/lib/services/electron-native.service.ts @@ -309,8 +309,14 @@ export class ElectronNativeService implements NativeService { }); } - selectSaveFilePath(defaultPath?: string): Promise { - return new Promise((resolve, reject) => { + selectSaveFilePath(defaultPath?: string): Promise<{ + canceled: boolean, + filePath: string + }> { + return new Promise<{ + canceled: boolean, + filePath: string + }>((resolve, reject) => { try { resolve( this.ipcRenderer.sendSync(FileChannel.SelectSaveFilePath, defaultPath) diff --git a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts index 43cc5328..e456dcb0 100644 --- a/projects/ucap-webmessenger-native/src/lib/services/native.service.ts +++ b/projects/ucap-webmessenger-native/src/lib/services/native.service.ts @@ -59,7 +59,10 @@ export abstract class NativeService { abstract openTargetItem(filePath?: string): Promise; abstract getPath(name: NativePathName): Promise; abstract selectDirectory(): Promise; - abstract selectSaveFilePath(defaultPath?: string): Promise; + abstract selectSaveFilePath(defaultPath?: string): Promise<{ + canceled: boolean, + filePath: string + }>; abstract executeProcess(executableName: string): Promise; diff --git a/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.html b/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.html index 61082e77..611dc245 100644 --- a/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.html +++ b/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.html @@ -58,9 +58,12 @@ + {{ inputTitle.value?.length || 0 }}/100