diff --git a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts index 850e4c04..d07d3af2 100644 --- a/projects/ucap-webmessenger-app/src/app/services/notification.service.ts +++ b/projects/ucap-webmessenger-app/src/app/services/notification.service.ts @@ -13,6 +13,7 @@ import { } from '@ucap-webmessenger/protocol-authentication'; import * as AuthenticationStore from '@app/store/account/authentication'; +import * as EventStore from '@app/store/messenger/event'; import { NGXLogger } from 'ngx-logger'; import { EventProtocolService, @@ -20,7 +21,8 @@ import { SendNotification, SSVC_TYPE_EVENT_READ_NOTI, SSVC_TYPE_EVENT_CANCEL_NOTI, - SSVC_TYPE_EVENT_DEL_RES + SSVC_TYPE_EVENT_DEL_RES, + Info } from '@ucap-webmessenger/protocol-event'; import { InfoProtocolService, @@ -105,6 +107,22 @@ export class AppNotificationService { 'Notification::eventProtocolService::SendNotification', noti ); + + const appendInfo: Info = { + seq: noti.seq, + type: noti.eventType, + senderSeq: noti.SENDER_SEQ, + sendDate: noti.sendDate, + sentMessage: noti.message, + receiverCount: noti.receiverCount + }; + + this.store.dispatch( + EventStore.newInfo({ + roomSeq: noti.roomSeq, + info: appendInfo + }) + ); } break; case SSVC_TYPE_EVENT_READ_NOTI: 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 f3e10511..25947104 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 @@ -25,6 +25,14 @@ export const infoFailure = createAction( props<{ error: any }>() ); +export const newInfo = createAction( + '[Messenger::Event] New Info', + props<{ + roomSeq: string; + info: Info; + }>() +); + export const appendInfoList = createAction( '[Messenger::Event] Append InfoList', 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 8ed7c2ed..7ee0293d 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 @@ -2,12 +2,19 @@ import { Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; -import { Store } from '@ngrx/store'; +import { Store, select } from '@ngrx/store'; import { NGXLogger } from 'ngx-logger'; import { of } from 'rxjs'; -import { tap, switchMap, map, catchError, exhaustMap } from 'rxjs/operators'; +import { + tap, + switchMap, + map, + catchError, + exhaustMap, + withLatestFrom +} from 'rxjs/operators'; import { InfoData, Info, @@ -27,9 +34,11 @@ import { send, sendSuccess, sendFailure, - appendInfoList + appendInfoList, + newInfo } from './actions'; import { SessionStorageService } from '@ucap-webmessenger/web-storage'; +import { RoomInfo } from '@ucap-webmessenger/protocol-room'; @Injectable() export class Effects { @@ -112,7 +121,28 @@ export class Effects { receiverCount: res.receiverCount }; - this.store.dispatch(appendInfoList({ info: appendInfo })); + this.store.dispatch( + newInfo({ roomSeq: res.roomSeq, info: appendInfo }) + ); + }) + ); + }, + { dispatch: false } + ); + + newInfo$ = createEffect( + () => { + return this.actions$.pipe( + ofType(newInfo), + withLatestFrom( + this.store.pipe( + select((state: any) => state.messenger.room.roomInfo as RoomInfo) + ) + ), + tap(([action, roomInfo]) => { + if (roomInfo.roomSeq === action.roomSeq) { + this.store.dispatch(appendInfoList({ info: action.info })); + } }) ); }, diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/models/info.ts b/projects/ucap-webmessenger-protocol-event/src/lib/models/info.ts index df8727f4..fa28fc20 100644 --- a/projects/ucap-webmessenger-protocol-event/src/lib/models/info.ts +++ b/projects/ucap-webmessenger-protocol-event/src/lib/models/info.ts @@ -8,7 +8,7 @@ export interface Info { // 발신자SEQ senderSeq: number; // 발신일시 - sendDate: Date; + sendDate: string; // 발신내용 sentMessage: string; // 수신자수 diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/protocols/info.ts b/projects/ucap-webmessenger-protocol-event/src/lib/protocols/info.ts index 5b38f074..80760f3c 100644 --- a/projects/ucap-webmessenger-protocol-event/src/lib/protocols/info.ts +++ b/projects/ucap-webmessenger-protocol-event/src/lib/protocols/info.ts @@ -63,7 +63,7 @@ export const decodeInfoData: ProtocolDecoder = ( seq: info[0], type: info[1] as EventType, senderSeq: Number(info[2]), - sendDate: new Date(info[3]), + sendDate: info[3], sentMessage: info[4], receiverCount: Number(info[5]) }); diff --git a/projects/ucap-webmessenger-protocol-event/src/lib/protocols/send.ts b/projects/ucap-webmessenger-protocol-event/src/lib/protocols/send.ts index 3c3865d2..adf98aeb 100644 --- a/projects/ucap-webmessenger-protocol-event/src/lib/protocols/send.ts +++ b/projects/ucap-webmessenger-protocol-event/src/lib/protocols/send.ts @@ -30,7 +30,7 @@ export interface SendResponse extends ProtocolResponse { // 이벤트타입(s) eventType: EventType; // 발생일시(s) - sendDate: Date; + sendDate: string; // 이벤트내용(s) message: string; // 수신자수 @@ -44,27 +44,27 @@ export interface SendResponse extends ProtocolResponse { } export interface SendNotification extends ProtocolNotification { - // 대화방SEQ(s) + /** 대화방SEQ(s) */ roomSeq: string; - // 이벤트SEQ(n) + /** 이벤트SEQ(n) */ seq: number; - // 이벤트타입(s) + /** 이벤트타입(s) */ eventType: EventType; - // 발생일시(s) + /** 발생일시(s) */ sendDate: string; - // 이벤트내용(s) + /** 이벤트내용(s) */ message: string; - // 수신자수 + /** 수신자수 */ receiverCount: number; - // 알림상태(s) PC 경우에만 관여됨 N: 푸시를 보내지 않은 이벤트 S: 푸시를 보낸 이벤트 + /** 알림상태(s) PC 경우에만 관여됨 N: 푸시를 보내지 않은 이벤트 S: 푸시를 보낸 이벤트 */ pushStatus: PushStatus; - // 강퇴 타입(s) + /** 강퇴 타입(s) */ ForcedExitType: string; - // 요청자 이름(s) + /** 요청자 이름(s) */ senderName: string; - // 사용자아이디(s) + /** 사용자아이디(s) */ id?: string; - // 회사코드(s) + /** 회사코드(s) */ companyCode?: string; } diff --git a/projects/ucap-webmessenger-util/src/lib/services/enviroment-util.service.spec.ts b/projects/ucap-webmessenger-util/src/lib/services/enviroment-util.service.spec.ts index dd7540ef..32fb3d07 100644 --- a/projects/ucap-webmessenger-util/src/lib/services/enviroment-util.service.spec.ts +++ b/projects/ucap-webmessenger-util/src/lib/services/enviroment-util.service.spec.ts @@ -1,16 +1,6 @@ import { TestBed } from '@angular/core/testing'; import { EnviromentUtilService } from './enviroment-util.service'; -import { interval, fromEvent, concat, merge, race, of, zip } from 'rxjs'; -import { - take, - map, - combineAll, - tap, - mapTo, - delay, - switchMap -} from 'rxjs/operators'; describe('EnviromentUtilService', () => { beforeEach(() => TestBed.configureTestingModule({})); @@ -19,87 +9,4 @@ describe('EnviromentUtilService', () => { const service: EnviromentUtilService = TestBed.get(EnviromentUtilService); expect(service).toBeTruthy(); }); - - // it('rxjs combineAll', () => { - // const source = interval(1000).pipe(take(2)); - // const example = source.pipe( - // map(sv => { - // console.log('sv', sv, new Date()); - - // return interval(1000).pipe( - // tap(ev => { - // console.log('sv', sv, 'ev', ev, new Date()); - // }), - // map(ev => `Result (${sv}): ${ev}`), - // take(3) - // ); - // }) - // ); - // const result = example.pipe(combineAll()); - - // result.subscribe(x => console.log('x', x, new Date())); - // }); - - // it('rxjs merge', () => { - // // emit every 2.5 seconds - // const first = interval(2500); - // // emit every 2 seconds - // const second = interval(2000); - // // emit every 1.5 seconds - // const third = interval(1500); - // // emit every 1 second - // const fourth = interval(1000); - - // // emit outputs from one observable - // const example = merge( - // first.pipe(mapTo('FIRST!')), - // second.pipe(mapTo('SECOND!')), - // third.pipe(mapTo('THIRD')), - // fourth.pipe(mapTo('FOURTH')) - // ); - // // output: "FOURTH", "THIRD", "SECOND!", "FOURTH", "FIRST!", "THIRD", "FOURTH" - // const subscribe = example.subscribe(val => console.log(val)); - // }); - - // it('rxjs race', () => { - // // take the first observable to emit - // const example = race( - // // emit every 1.5s - // interval(1500).pipe(mapTo('1.5s won!')), - // // emit every 1s - // interval(1000).pipe(mapTo('1s won!')), - // // emit every 2s - // interval(2000).pipe(mapTo('2s won!')), - // // emit every 2.5s - // interval(2500).pipe(mapTo('2.5s won!')) - // ); - // // output: "1s won!"..."1s won!"...etc - // const subscribe = example.subscribe(val => console.log(val)); - // }); - - // it('rxjs zip', () => { - // const sourceOne = of('Hello'); - // const sourceTwo = of('World!'); - // const sourceThree = of('Goodbye'); - // const sourceFour = of('World!'); - // // wait until all observables have emitted a value then emit all as an array - // const example = zip( - // sourceOne, - // sourceTwo.pipe(delay(2000)), - // sourceThree.pipe(delay(1000)), - // sourceFour.pipe(delay(3000)) - // ); - // // output: ["Hello", "World!", "Goodbye", "World!"] - // const subscribe = example.subscribe(val => console.log(val)); - // }); - - it('rxjs zip', () => { - const switched = of(1, 2, 3).pipe( - switchMap((x: number) => { - console.log('x', x); - return of(x, x ** 2, x ** 3); - }) - ); - switched.subscribe(x => console.log(x)); - }); });