effects for bulk-info is implemented

This commit is contained in:
병준 박 2019-10-02 18:09:39 +09:00
parent a201536b02
commit 58ded38772
13 changed files with 202 additions and 41 deletions

View File

@ -1 +1 @@
Chat
<div *ngFor="let room of roomList$ | async">{{ room.finalEventMessage }}</div>

View File

@ -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<RoomInfo[]>;
ngOnInit() {}
constructor(private store: Store<any>, private logger: NGXLogger) {}
ngOnInit() {
this.roomList$ = this.store.pipe(
select(AppStore.MessengerSelector.SyncSelector.roomList)
);
}
}

View File

@ -127,7 +127,7 @@ export class AppMessengerResolver implements Resolve<void> {
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<void> {
),
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<void> {
loginInfo: loginRes
})
);
console.log('next');
resolve();
},
err => {
console.log('err', err);
reject(err);
},
() => {
console.log('complete');
}
);
});

View File

@ -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<any>[] = [ChatStore.Effects, SyncStore.Effects];
export const effects: Type<any>[] = [
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<S>(selector: Selector<any, State>) {
(state: State) => state.chat
)
),
StatusSelector: StatusStore.selectors(
createSelector(
selector,
(state: State) => state.status
)
),
SyncSelector: SyncStore.selectors(
createSelector(
selector,

View File

@ -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<BulkInfoRequest>()
);
export const bulkInfoSuccess = createAction(
'[Messenger::Status] Bulk Info Success',
props<{ statusBulkInfoList: StatusBulkInfo[] }>()
);
export const bulkInfoFailure = createAction(
'[Messenger::Status] Bulk Info Failure',
props<{ error: any }>()
);

View File

@ -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<any>,
private statusProtocolService: StatusProtocolService,
private logger: NGXLogger
) {}
}

View File

@ -0,0 +1,4 @@
export * from './actions';
export * from './effects';
export * from './reducers';
export * from './state';

View File

@ -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
};
})
);

View File

@ -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<S>(selector: Selector<any, State>) {
return {
statusBulkInfoList: createSelector(
selector,
(state: State) => state.statusBulkInfoList
)
};
}

View File

@ -127,28 +127,28 @@ export class Effects {
{ dispatch: false }
);
buddy2SuccessPostRoom$ = createEffect(() =>
this.actions$.pipe(
ofType(buddy2Success),
map(action => {
const loginInfo = this.sessionStorageService.get<LoginInfo>(
KEY_LOGIN_INFO
);
// buddy2SuccessPostRoom$ = createEffect(() =>
// this.actions$.pipe(
// ofType(buddy2Success),
// map(action => {
// const loginInfo = this.sessionStorageService.get<LoginInfo>(
// 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(
() => {

View File

@ -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;
}

View File

@ -28,7 +28,7 @@ import {
encodeBulkInfo,
decodeBulkInfo,
decodeBulkInfoData
} from '../models/bulk';
} from '../models/bulk-info';
import { BuddyResponse, decodeBuddy } from '../models/buddy';
import {
MessageUpdateRequest,

View File

@ -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';