From fcba726a2f5972c201416eddfe8fcd1a5d4a14b4 Mon Sep 17 00:00:00 2001 From: leejh Date: Mon, 28 Oct 2019 18:03:27 +0900 Subject: [PATCH] =?UTF-8?q?MASS=20TEXT=20=EC=A0=84=EB=8B=AC=20=EC=88=98?= =?UTF-8?q?=EC=8B=A0=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/lib/apis/mass-talk-download.ts | 27 +++++--- .../src/lib/apis/mass-talk-save.ts | 44 ++++++++++--- .../src/lib/services/common-api.service.ts | 6 +- .../src/lib/types/status-code.type.ts | 3 +- .../src/lib/utils/json.util.ts | 20 ++++++ .../ucap-webmessenger-api/src/public-api.ts | 1 + .../components/messages.component.ts | 36 ++++++++--- .../src/app/store/messenger/event/actions.ts | 16 +++++ .../src/app/store/messenger/event/effects.ts | 64 ++++++++++++++++++- .../src/app/store/messenger/sync/reducers.ts | 14 ++++ .../src/lib/type/maximum-range.type.ts | 4 ++ .../ucap-webmessenger-core/src/public-api.ts | 1 + .../components/message-box/mass.component.ts | 5 +- .../src/lib/utils/string.util.ts | 22 +++++++ 14 files changed, 229 insertions(+), 34 deletions(-) create mode 100644 projects/ucap-webmessenger-api/src/lib/utils/json.util.ts create mode 100644 projects/ucap-webmessenger-core/src/lib/type/maximum-range.type.ts diff --git a/projects/ucap-webmessenger-api-common/src/lib/apis/mass-talk-download.ts b/projects/ucap-webmessenger-api-common/src/lib/apis/mass-talk-download.ts index cfbdc407..b786c9d1 100644 --- a/projects/ucap-webmessenger-api-common/src/lib/apis/mass-talk-download.ts +++ b/projects/ucap-webmessenger-api-common/src/lib/apis/mass-talk-download.ts @@ -4,8 +4,11 @@ import { APIResponse, APIEncoder, APIDecoder, - ParameterUtil + ParameterUtil, + JsonAnalization, + StatusCode } from '@ucap-webmessenger/api'; +import { JsonObject } from 'type-fest'; export interface MassTalkDownloadRequest extends APIRequest { userSeq: number; @@ -36,11 +39,19 @@ export const encodeMassTalkDownload: APIEncoder = ( export const decodeMassTalkDownload: APIDecoder = ( res: any ) => { - return { - statusCode: res.StatusCode, - errorMessage: res.ErrorMessage, - content: res.Content, - userName: res.UserName, - regDate: res.RegDate - } as MassTalkDownloadResponse; + try { + const json: JsonObject | Error = JsonAnalization.receiveAnalization(res); + return { + statusCode: json.StatusCode, + errorMessage: json.ErrorMessage, + content: json.Content, + userName: json.UserName, + regDate: json.RegDate + } as MassTalkDownloadResponse; + } catch (e) { + return { + statusCode: StatusCode.Fail, + errorMessage: e + } as MassTalkDownloadResponse; + } }; diff --git a/projects/ucap-webmessenger-api-common/src/lib/apis/mass-talk-save.ts b/projects/ucap-webmessenger-api-common/src/lib/apis/mass-talk-save.ts index 648c3711..3f8a4fa4 100644 --- a/projects/ucap-webmessenger-api-common/src/lib/apis/mass-talk-save.ts +++ b/projects/ucap-webmessenger-api-common/src/lib/apis/mass-talk-save.ts @@ -4,25 +4,35 @@ import { APIResponse, APIEncoder, APIDecoder, - ParameterUtil + ParameterUtil, + StatusCode, + JsonAnalization } from '@ucap-webmessenger/api'; +import { JsonObject } from 'type-fest'; export interface MassTalkSaveRequest extends APIRequest { - userSeq: string; + userSeq: number; deviceType: DeviceType; token: string; content?: string; - roomId?: string; + roomSeq?: string; } export interface MassTalkSaveResponse extends APIResponse { - EventMassSEQ?: string; - RoomID?: string; - RegDate?: string; - Content?: string; + eventMassSeq?: string; + roomID?: string; + regDate?: string; + content?: string; + returnJson?: any; } -const massTalkSaveEncodeMap = {}; +const massTalkSaveEncodeMap = { + userSeq: 'p_user_seq', + deviceType: 'p_device_type', + token: 'p_token', + content: 'p_content', + roomSeq: 'p_room_id' +}; export const encodeMassTalkSave: APIEncoder = ( req: MassTalkSaveRequest @@ -33,5 +43,21 @@ export const encodeMassTalkSave: APIEncoder = ( export const decodeMassTalkSave: APIDecoder = ( res: any ) => { - return {} as MassTalkSaveResponse; + try { + const json: JsonObject | Error = JsonAnalization.receiveAnalization(res); + return { + statusCode: json.StatusCode, + errorMessage: json.ErrorMessage, + content: json.Content, + eventMassSeq: json.EventMassSeq, + regDate: json.RegDate, + roomID: json.RoomID, + returnJson: res + } as MassTalkSaveResponse; + } catch (e) { + return { + statusCode: StatusCode.Fail, + errorMessage: e + } as MassTalkSaveResponse; + } }; 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 7e401ac2..bbd7b547 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 @@ -134,7 +134,8 @@ export class CommonApiService { this.moduleConfig.urls.massTalkDownload, {}, { - params: encodeMassTalkDownload(req) + params: encodeMassTalkDownload(req), + responseType: 'text' as 'json' } ) .pipe(map(res => decodeMassTalkDownload(res))); @@ -148,7 +149,8 @@ export class CommonApiService { this.moduleConfig.urls.massTalkSave, {}, { - params: encodeMassTalkSave(req) + params: encodeMassTalkSave(req), + responseType: 'text' as 'json' } ) .pipe(map(res => decodeMassTalkSave(res))); diff --git a/projects/ucap-webmessenger-api/src/lib/types/status-code.type.ts b/projects/ucap-webmessenger-api/src/lib/types/status-code.type.ts index a5c41a9f..ec9005b5 100644 --- a/projects/ucap-webmessenger-api/src/lib/types/status-code.type.ts +++ b/projects/ucap-webmessenger-api/src/lib/types/status-code.type.ts @@ -1,3 +1,4 @@ export enum StatusCode { - Success = '200' + Success = '200', + Fail = '500' } diff --git a/projects/ucap-webmessenger-api/src/lib/utils/json.util.ts b/projects/ucap-webmessenger-api/src/lib/utils/json.util.ts new file mode 100644 index 00000000..25f8964a --- /dev/null +++ b/projects/ucap-webmessenger-api/src/lib/utils/json.util.ts @@ -0,0 +1,20 @@ +import { JsonObject } from 'type-fest'; + +export class JsonAnalization { + public static receiveAnalization(jsonStr: string): JsonObject { + const startJson = jsonStr.indexOf('{'); + const endJson = jsonStr.lastIndexOf('}'); + + if (startJson >= 0 && startJson < endJson) { + jsonStr = jsonStr + .substring(startJson, endJson + 1) + .replace(/\n"/gi, '"') + .replace(/\n}/gi, '}') + .replace(/\n/gi, '\\n'); + + return JSON.parse(jsonStr); + } else { + throw new Error('Invalid Json String'); + } + } +} diff --git a/projects/ucap-webmessenger-api/src/public-api.ts b/projects/ucap-webmessenger-api/src/public-api.ts index 145c80d0..1482b72c 100644 --- a/projects/ucap-webmessenger-api/src/public-api.ts +++ b/projects/ucap-webmessenger-api/src/public-api.ts @@ -6,5 +6,6 @@ export * from './lib/apis/api'; export * from './lib/types/status-code.type'; +export * from './lib/utils/json.util'; export * from './lib/utils/parameter.util'; export * from './lib/utils/url.util'; 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 3ca24a96..6fb1a60f 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 @@ -50,6 +50,7 @@ import { CreateChatDialogData, CreateChatDialogResult } from '../dialogs/chat/create-chat.dialog.component'; +import { Maximum_Range } from '@ucap-webmessenger/core'; @Component({ selector: 'app-layout-messenger-messages', @@ -184,16 +185,31 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewChecked { selectContact() {} onSendMessage(message: string) { - this.store.dispatch( - EventStore.send({ - senderSeq: this.loginRes.userSeq, - req: { - roomSeq: this.roomInfo.roomSeq, - eventType: EventType.Character, - sentMessage: message - } - }) - ); + if (message.trim().length > Maximum_Range.MassText) { + // MASS TEXT + this.store.dispatch( + EventStore.sendMass({ + senderSeq: this.loginRes.userSeq, + req: { + roomSeq: this.roomInfo.roomSeq, + eventType: EventType.MassText, + // sentMessage: message.replace(/\n/gi, '\r\n') + sentMessage: message + } + }) + ); + } else { + this.store.dispatch( + EventStore.send({ + senderSeq: this.loginRes.userSeq, + req: { + roomSeq: this.roomInfo.roomSeq, + eventType: EventType.Character, + sentMessage: message + } + }) + ); + } } onClickReceiveAlarm() { diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/event/actions.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/event/actions.ts index 69e78390..7ae76dc2 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/event/actions.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/event/actions.ts @@ -95,6 +95,22 @@ export const forwardAfterRoomOpen = createAction( }>() ); +export const sendMass = createAction( + '[Messenger::Event] Send Mass', + props<{ senderSeq: number; req: SendRequest }>() +); +export const sendMassSuccess = createAction( + '[Messenger::Event] Send Mass Success', + props<{ + senderSeq: number; + res: SendResponse; + }>() +); +export const sendMassFailure = createAction( + '[Messenger::Event] Send Mass Failure', + props<{ error: any }>() +); + export const read = createAction( '[Messenger::Event] read', props() diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/event/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/event/effects.ts index 6df3a803..7e928630 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/event/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/event/effects.ts @@ -1,3 +1,8 @@ +import { + CommonApiService, + MassTalkSaveRequest +} from '@ucap-webmessenger/api-common'; +import { KEY_ENVIRONMENTS_INFO } from './../../../types/environment.type'; import { Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; @@ -25,7 +30,8 @@ import { SendResponse, ReadResponse, DelResponse, - CancelResponse + CancelResponse, + EventType } from '@ucap-webmessenger/protocol-event'; import * as ChatStore from '@app/store/messenger/chat'; @@ -54,7 +60,9 @@ import { cancelFailure, forward, forwardFailure, - forwardAfterRoomOpen + forwardAfterRoomOpen, + sendMass, + sendMassFailure } from './actions'; import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { @@ -62,9 +70,12 @@ import { RoomProtocolService, OpenResponse } from '@ucap-webmessenger/protocol-room'; -import { LoginInfo, KEY_LOGIN_INFO } from '@app/types'; +import { LoginInfo, KEY_LOGIN_INFO, EnvironmentsInfo } from '@app/types'; import { Dictionary } from '@ngrx/entity'; import { openSuccess, openFailure } from '../room'; +import { LoginResponse } from '@ucap-webmessenger/protocol-authentication'; +import { KEY_LOGIN_RES_INFO } from '@app/types/login-res-info.type'; +import { StatusCode } from '@ucap-webmessenger/api'; @Injectable() export class Effects { @@ -289,6 +300,52 @@ export class Effects { ) ); + sendMass$ = createEffect( + () => { + return this.actions$.pipe( + ofType(sendMass), + exhaustMap(action => { + const loginResInfo: LoginResponse = this.sessionStorageService.get< + LoginResponse + >(KEY_LOGIN_RES_INFO); + + const environmentsInfo = this.sessionStorageService.get< + EnvironmentsInfo + >(KEY_ENVIRONMENTS_INFO); + + const req: MassTalkSaveRequest = { + userSeq: loginResInfo.userSeq, + deviceType: environmentsInfo.deviceType, + token: loginResInfo.tokenString, + content: action.req.sentMessage, + roomSeq: action.req.roomSeq + }; + + return this.commonApiService.massTalkSave(req).pipe( + map(res => { + if (res.statusCode === StatusCode.Success) { + this.store.dispatch( + send({ + senderSeq: action.senderSeq, + req: { + roomSeq: res.roomID, + eventType: EventType.MassText, + sentMessage: res.returnJson + } + }) + ); + } else { + this.store.dispatch(sendMassFailure({ error: res })); + } + }), + catchError(error => of(sendMassFailure({ error }))) + ); + }) + ); + }, + { dispatch: false } + ); + newInfo$ = createEffect( () => { return this.actions$.pipe( @@ -428,6 +485,7 @@ export class Effects { constructor( private actions$: Actions, private store: Store, + private commonApiService: CommonApiService, private eventProtocolService: EventProtocolService, private roomProtocolService: RoomProtocolService, private sessionStorageService: SessionStorageService, diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts index 7fe5b51b..71759188 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/reducers.ts @@ -1,3 +1,4 @@ +import { JsonObject } from 'type-fest'; import { createReducer, on } from '@ngrx/store'; import { initialState, @@ -30,6 +31,7 @@ import * as RoomStore from '@app/store/messenger/room'; import { RoomInfo } from '@ucap-webmessenger/protocol-room'; import { EventType } from '@ucap-webmessenger/protocol-event'; import { FileType } from '@ucap-webmessenger/protocol-file'; +import { JsonAnalization } from '@ucap-webmessenger/api'; export const reducer = createReducer( initialState, @@ -119,6 +121,18 @@ export const reducer = createReducer( case EventType.VideoConference: finalEventMessage = '화상회의'; break; + case EventType.MassText: + { + try { + const json: JsonObject | Error = JsonAnalization.receiveAnalization( + finalEventMessage + ); + finalEventMessage = json.Content.toString(); + } catch (e) { + finalEventMessage = '대용량 텍스트'; + } + } + break; } const roomInfo = { ...state.room.entities[action.roomSeq], diff --git a/projects/ucap-webmessenger-core/src/lib/type/maximum-range.type.ts b/projects/ucap-webmessenger-core/src/lib/type/maximum-range.type.ts new file mode 100644 index 00000000..ad1c7d03 --- /dev/null +++ b/projects/ucap-webmessenger-core/src/lib/type/maximum-range.type.ts @@ -0,0 +1,4 @@ +export enum Maximum_Range { + MassText = 800, + ChatRoom = 300 +} diff --git a/projects/ucap-webmessenger-core/src/public-api.ts b/projects/ucap-webmessenger-core/src/public-api.ts index 879e03a7..e02f3957 100644 --- a/projects/ucap-webmessenger-core/src/public-api.ts +++ b/projects/ucap-webmessenger-core/src/public-api.ts @@ -12,6 +12,7 @@ export * from './lib/type/device-devision.type'; export * from './lib/type/device-type.type'; export * from './lib/type/file-transfer-permissions.type'; export * from './lib/type/locale-code.type'; +export * from './lib/type/maximum-range.type'; export * from './lib/type/notification-method.type'; export * from './lib/type/organization-chart-permissions.type'; export * from './lib/type/push-type.type'; diff --git a/projects/ucap-webmessenger-ui-chat/src/lib/components/message-box/mass.component.ts b/projects/ucap-webmessenger-ui-chat/src/lib/components/message-box/mass.component.ts index 739a3eeb..1a11d3ce 100644 --- a/projects/ucap-webmessenger-ui-chat/src/lib/components/message-box/mass.component.ts +++ b/projects/ucap-webmessenger-ui-chat/src/lib/components/message-box/mass.component.ts @@ -3,6 +3,7 @@ import { Info } from '@ucap-webmessenger/protocol-event'; import { NGXLogger } from 'ngx-logger'; import { StatusCode } from '@ucap-webmessenger/api'; import { MassTextInfo } from '../../models/mass-talk-info.json'; +import { StringUtil } from '@ucap-webmessenger/ui'; @Component({ selector: 'ucap-chat-message-box-mass', @@ -24,7 +25,9 @@ export class MassComponent implements OnInit { ngOnInit() { try { - const contentJson: MassTextInfo = JSON.parse(this.message.sentMessage); + const contentJson: MassTextInfo = StringUtil.receiveAnalization( + this.message.sentMessage + ); if (contentJson.StatusCode === StatusCode.Success) { this.content = contentJson.Content; } else { diff --git a/projects/ucap-webmessenger-ui/src/lib/utils/string.util.ts b/projects/ucap-webmessenger-ui/src/lib/utils/string.util.ts index c281f032..d8f9f272 100644 --- a/projects/ucap-webmessenger-ui/src/lib/utils/string.util.ts +++ b/projects/ucap-webmessenger-ui/src/lib/utils/string.util.ts @@ -1,3 +1,5 @@ +import { JsonObject } from 'type-fest'; + export class StringUtil { /** * linefeed >
@@ -33,6 +35,26 @@ export class StringUtil { } } + /** + * Json String Analization. + */ + public static receiveAnalization(jsonStr: string): JsonObject { + const startJson = jsonStr.indexOf('{'); + const endJson = jsonStr.lastIndexOf('}'); + + if (startJson >= 0 && startJson < endJson) { + jsonStr = jsonStr + .substring(startJson, endJson + 1) + .replace(/\n"/gi, '"') + .replace(/\n}/gi, '}') + .replace(/\n/gi, '\\n'); + + return JSON.parse(jsonStr); + } else { + throw new Error('Invalid Json String'); + } + } + /** * date formater */