From 58ded38772a1041d6edcb924e6ec52c147ba042b Mon Sep 17 00:00:00 2001 From: Richard Park Date: Wed, 2 Oct 2019 18:09:39 +0900 Subject: [PATCH] effects for bulk-info is implemented --- .../left-sidenav/chat.component.html | 2 +- .../components/left-sidenav/chat.component.ts | 15 +++- .../src/app/resolvers/messenger.resolver.ts | 18 +++-- .../src/app/store/messenger/index.ts | 15 +++- .../src/app/store/messenger/status/actions.ts | 20 +++++ .../src/app/store/messenger/status/effects.ts | 77 +++++++++++++++++++ .../src/app/store/messenger/status/index.ts | 4 + .../app/store/messenger/status/reducers.ts | 13 ++++ .../src/app/store/messenger/status/state.ts | 19 +++++ .../src/app/store/messenger/sync/effects.ts | 42 +++++----- .../src/lib/models/{bulk.ts => bulk-info.ts} | 14 ++-- .../lib/services/status-protocol.service.ts | 2 +- .../src/public-api.ts | 2 +- 13 files changed, 202 insertions(+), 41 deletions(-) create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/status/actions.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/status/effects.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/status/index.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/status/state.ts rename projects/ucap-webmessenger-protocol-status/src/lib/models/{bulk.ts => bulk-info.ts} (93%) diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/chat.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/chat.component.html index eb05330a..e9b45110 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/chat.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/chat.component.html @@ -1 +1 @@ -Chat +
{{ room.finalEventMessage }}
diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/chat.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/chat.component.ts index 3ed1c460..65139633 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/chat.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/chat.component.ts @@ -1,5 +1,10 @@ import { Component, OnInit } from '@angular/core'; import { ucapAnimations } from '@ucap-webmessenger/ui'; +import { NGXLogger } from 'ngx-logger'; +import { Store, select } from '@ngrx/store'; +import { Observable } from 'rxjs'; +import { RoomInfo } from '@ucap-webmessenger/protocol-room'; +import * as AppStore from '@app/store'; @Component({ selector: 'app-layout-chat-left-sidenav-chat', @@ -8,7 +13,13 @@ import { ucapAnimations } from '@ucap-webmessenger/ui'; animations: ucapAnimations }) export class ChatComponent implements OnInit { - constructor() {} + roomList$: Observable; - ngOnInit() {} + constructor(private store: Store, private logger: NGXLogger) {} + + ngOnInit() { + this.roomList$ = this.store.pipe( + select(AppStore.MessengerSelector.SyncSelector.roomList) + ); + } } diff --git a/projects/ucap-webmessenger-app/src/app/resolvers/messenger.resolver.ts b/projects/ucap-webmessenger-app/src/app/resolvers/messenger.resolver.ts index 7652158b..038c87e7 100644 --- a/projects/ucap-webmessenger-app/src/app/resolvers/messenger.resolver.ts +++ b/projects/ucap-webmessenger-app/src/app/resolvers/messenger.resolver.ts @@ -127,7 +127,7 @@ export class AppMessengerResolver implements Resolve { this.optionProtocolService.regView({}) ]) ), - tap(([authRes, regViewRes]) => { + map(([authRes, regViewRes]) => { this.store.dispatch( OptionStore.regViewSuccess({ res: regViewRes }) ); @@ -139,11 +139,20 @@ export class AppMessengerResolver implements Resolve { ), this.store.pipe( select(AppStore.MessengerSelector.SyncSelector.group2SyncDate) + ), + this.store.pipe( + select(AppStore.MessengerSelector.SyncSelector.roomSyncDate) ) ), - map(([[], buddy2SyncDate, group2SyncDate]) => { + map(([_, buddy2SyncDate, group2SyncDate, roomSyncDate]) => { this.store.dispatch(SyncStore.buddy2({ syncDate: buddy2SyncDate })); this.store.dispatch(SyncStore.group2({ syncDate: group2SyncDate })); + this.store.dispatch( + SyncStore.room({ + syncDate: roomSyncDate, + localeCode: loginInfo.localeCode + }) + ); }), catchError(err => { return throwError(err); @@ -156,15 +165,10 @@ export class AppMessengerResolver implements Resolve { loginInfo: loginRes }) ); - console.log('next'); resolve(); }, err => { - console.log('err', err); reject(err); - }, - () => { - console.log('complete'); } ); }); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/index.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/index.ts index 7d85092c..be22c53c 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/index.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/index.ts @@ -2,18 +2,25 @@ import { Type } from '@angular/core'; import { Action, combineReducers, Selector, createSelector } from '@ngrx/store'; import * as ChatStore from './chat'; +import * as StatusStore from './status'; import * as SyncStore from './sync'; export interface State { chat: ChatStore.State; + status: StatusStore.State; sync: SyncStore.State; } -export const effects: Type[] = [ChatStore.Effects, SyncStore.Effects]; +export const effects: Type[] = [ + ChatStore.Effects, + StatusStore.Effects, + SyncStore.Effects +]; export function reducers(state: State | undefined, action: Action) { return combineReducers({ chat: ChatStore.reducer, + status: StatusStore.reducer, sync: SyncStore.reducer })(state, action); } @@ -26,6 +33,12 @@ export function selectors(selector: Selector) { (state: State) => state.chat ) ), + StatusSelector: StatusStore.selectors( + createSelector( + selector, + (state: State) => state.status + ) + ), SyncSelector: SyncStore.selectors( createSelector( selector, diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/actions.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/actions.ts new file mode 100644 index 00000000..4dc37685 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/actions.ts @@ -0,0 +1,20 @@ +import { createAction, props } from '@ngrx/store'; +import { + BulkInfoRequest, + StatusBulkInfo +} from '@ucap-webmessenger/protocol-status'; + +export const bulkInfo = createAction( + '[Messenger::Status] Bulk Info', + props() +); + +export const bulkInfoSuccess = createAction( + '[Messenger::Status] Bulk Info Success', + props<{ statusBulkInfoList: StatusBulkInfo[] }>() +); + +export const bulkInfoFailure = createAction( + '[Messenger::Status] Bulk Info Failure', + props<{ error: any }>() +); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/effects.ts new file mode 100644 index 00000000..60f1c708 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/effects.ts @@ -0,0 +1,77 @@ +import { Injectable } from '@angular/core'; + +import { Actions, createEffect, ofType } from '@ngrx/effects'; + +import { Store } from '@ngrx/store'; + +import { NGXLogger } from 'ngx-logger'; +import * as SyncStore from '@app/store/messenger/sync'; +import { bulkInfo, bulkInfoSuccess, bulkInfoFailure } from './actions'; +import { tap, switchMap, map, catchError } from 'rxjs/operators'; +import { + StatusProtocolService, + SSVC_TYPE_STATUS_BULK_INFO_DATA, + SSVC_TYPE_STATUS_BULK_INFO_RES, + BulkInfoData, + StatusBulkInfo +} from '@ucap-webmessenger/protocol-status'; +import { of } from 'rxjs'; + +@Injectable() +export class Effects { + buddy2SuccessPostBulk$ = createEffect(() => + this.actions$.pipe( + ofType(SyncStore.buddy2Success), + map(params => { + const userSeqList: number[] = []; + for (const buddy of params.buddyList) { + userSeqList.push(buddy.seq); + } + + return bulkInfo({ divCd: 'bulk', userSeqs: userSeqList }); + }) + ) + ); + + bulkInfo$ = createEffect( + () => { + let statusBulkInfoList: StatusBulkInfo[]; + + return this.actions$.pipe( + ofType(bulkInfo), + tap(() => { + statusBulkInfoList = []; + }), + switchMap(req => { + return this.statusProtocolService.bulkInfo(req).pipe( + map(res => { + switch (res.Type) { + case SSVC_TYPE_STATUS_BULK_INFO_DATA: + statusBulkInfoList.push( + ...(res as BulkInfoData).statusBulkInfos + ); + break; + case SSVC_TYPE_STATUS_BULK_INFO_RES: + this.store.dispatch( + bulkInfoSuccess({ + statusBulkInfoList + }) + ); + break; + } + }), + catchError(error => of(bulkInfoFailure({ error }))) + ); + }) + ); + }, + { dispatch: false } + ); + + constructor( + private actions$: Actions, + private store: Store, + private statusProtocolService: StatusProtocolService, + private logger: NGXLogger + ) {} +} diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/index.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/index.ts new file mode 100644 index 00000000..2663cade --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/index.ts @@ -0,0 +1,4 @@ +export * from './actions'; +export * from './effects'; +export * from './reducers'; +export * from './state'; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts new file mode 100644 index 00000000..91e6f681 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts @@ -0,0 +1,13 @@ +import { createReducer, on } from '@ngrx/store'; +import { initialState } from './state'; +import { bulkInfoSuccess } from './actions'; + +export const reducer = createReducer( + initialState, + on(bulkInfoSuccess, (state, action) => { + return { + ...state, + statusBulkInfoList: action.statusBulkInfoList + }; + }) +); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/status/state.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/status/state.ts new file mode 100644 index 00000000..3a0c1767 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/status/state.ts @@ -0,0 +1,19 @@ +import { Selector, createSelector } from '@ngrx/store'; +import { StatusBulkInfo } from '@ucap-webmessenger/protocol-status'; + +export interface State { + statusBulkInfoList: StatusBulkInfo[]; +} + +export const initialState: State = { + statusBulkInfoList: [] +}; + +export function selectors(selector: Selector) { + return { + statusBulkInfoList: createSelector( + selector, + (state: State) => state.statusBulkInfoList + ) + }; +} diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts index b938e874..f8a939e7 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/sync/effects.ts @@ -127,28 +127,28 @@ export class Effects { { dispatch: false } ); - buddy2SuccessPostRoom$ = createEffect(() => - this.actions$.pipe( - ofType(buddy2Success), - map(action => { - const loginInfo = this.sessionStorageService.get( - KEY_LOGIN_INFO - ); + // buddy2SuccessPostRoom$ = createEffect(() => + // this.actions$.pipe( + // ofType(buddy2Success), + // map(action => { + // const loginInfo = this.sessionStorageService.get( + // KEY_LOGIN_INFO + // ); - return loginInfo.localeCode; - }), - withLatestFrom( - this.store.pipe( - select(state => { - return state.messenger.sync.roomSyncDate as string; - }) - ) - ), - map(([localeCode, roomSyncDate]) => - room({ syncDate: roomSyncDate, localeCode }) - ) - ) - ); + // return loginInfo.localeCode; + // }), + // withLatestFrom( + // this.store.pipe( + // select(state => { + // return state.messenger.sync.roomSyncDate as string; + // }) + // ) + // ), + // map(([localeCode, roomSyncDate]) => + // room({ syncDate: roomSyncDate, localeCode }) + // ) + // ) + // ); room$ = createEffect( () => { diff --git a/projects/ucap-webmessenger-protocol-status/src/lib/models/bulk.ts b/projects/ucap-webmessenger-protocol-status/src/lib/models/bulk-info.ts similarity index 93% rename from projects/ucap-webmessenger-protocol-status/src/lib/models/bulk.ts rename to projects/ucap-webmessenger-protocol-status/src/lib/models/bulk-info.ts index f6cd03ae..0a9d9bc1 100644 --- a/projects/ucap-webmessenger-protocol-status/src/lib/models/bulk.ts +++ b/projects/ucap-webmessenger-protocol-status/src/lib/models/bulk-info.ts @@ -17,9 +17,9 @@ import { } from '../types/terminal-status.type'; export interface BulkInfoRequest extends ProtocolRequest { - // DivCD(s) + /** DivCD(s) */ divCd: string; - // 사용자SEQ(n)... + /** 사용자SEQ(n)[] */ userSeqs: number[]; } export interface StatusBulkInfo extends StatusInfo { @@ -32,19 +32,19 @@ export interface StatusBulkInfo extends StatusInfo { // 상태코드(Mobile화상) // 상태코드(iMessenger) - // 단말상태정보(s) + /** 단말상태정보(s) */ terminalStatus: TerminalStatusInfo; - // 단말상태번호(n) + /** 단말상태번호(n) */ terminalStatusNumber: TerminalStatusNumber; } export interface BulkInfoData extends ProtocolStream { - // DivCD(s) + /** DivCD(s) */ divCd: string; - // {상태정보Bulk}... + /** {상태정보Bulk}... */ statusBulkInfos: StatusBulkInfo[]; } export interface BulkInfoResponse extends ProtocolResponse { - // DivCD(s) + /** DivCD(s) */ divCd: string; } diff --git a/projects/ucap-webmessenger-protocol-status/src/lib/services/status-protocol.service.ts b/projects/ucap-webmessenger-protocol-status/src/lib/services/status-protocol.service.ts index 04c41a72..02c8469e 100644 --- a/projects/ucap-webmessenger-protocol-status/src/lib/services/status-protocol.service.ts +++ b/projects/ucap-webmessenger-protocol-status/src/lib/services/status-protocol.service.ts @@ -28,7 +28,7 @@ import { encodeBulkInfo, decodeBulkInfo, decodeBulkInfoData -} from '../models/bulk'; +} from '../models/bulk-info'; import { BuddyResponse, decodeBuddy } from '../models/buddy'; import { MessageUpdateRequest, diff --git a/projects/ucap-webmessenger-protocol-status/src/public-api.ts b/projects/ucap-webmessenger-protocol-status/src/public-api.ts index 037c6d9b..0734d407 100644 --- a/projects/ucap-webmessenger-protocol-status/src/public-api.ts +++ b/projects/ucap-webmessenger-protocol-status/src/public-api.ts @@ -3,7 +3,7 @@ */ export * from './lib/models/buddy'; -export * from './lib/models/bulk'; +export * from './lib/models/bulk-info'; export * from './lib/models/message-update'; export * from './lib/models/status'; export * from './lib/models/subscribe';