event effect is implemented
This commit is contained in:
parent
9aae0885aa
commit
abd87579ef
|
@ -0,0 +1,24 @@
|
||||||
|
import { createAction, props } from '@ngrx/store';
|
||||||
|
import {
|
||||||
|
InfoRequest,
|
||||||
|
Info,
|
||||||
|
InfoResponse
|
||||||
|
} from '@ucap-webmessenger/protocol-event';
|
||||||
|
|
||||||
|
export const info = createAction(
|
||||||
|
'[Messenger::Event] Info',
|
||||||
|
props<InfoRequest>()
|
||||||
|
);
|
||||||
|
|
||||||
|
export const infoSuccess = createAction(
|
||||||
|
'[Messenger::Event] Info Success',
|
||||||
|
props<{
|
||||||
|
infoList: Info[];
|
||||||
|
res: InfoResponse;
|
||||||
|
}>()
|
||||||
|
);
|
||||||
|
|
||||||
|
export const infoFailure = createAction(
|
||||||
|
'[Messenger::Event] Info Failure',
|
||||||
|
props<{ error: any }>()
|
||||||
|
);
|
|
@ -0,0 +1,81 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
||||||
|
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
|
||||||
|
import { NGXLogger } from 'ngx-logger';
|
||||||
|
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
import { tap, switchMap, map, catchError } from 'rxjs/operators';
|
||||||
|
import {
|
||||||
|
InfoData,
|
||||||
|
Info,
|
||||||
|
InfoResponse,
|
||||||
|
EventProtocolService,
|
||||||
|
SSVC_TYPE_EVENT_INFO_DATA,
|
||||||
|
SSVC_TYPE_EVENT_INFO_RES
|
||||||
|
} from '@ucap-webmessenger/protocol-event';
|
||||||
|
|
||||||
|
import * as ChatStore from '@app/store/messenger/chat';
|
||||||
|
|
||||||
|
import { info, infoSuccess, infoFailure } from './actions';
|
||||||
|
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class Effects {
|
||||||
|
selectedRoomForInfo$ = createEffect(() =>
|
||||||
|
this.actions$.pipe(
|
||||||
|
ofType(ChatStore.selectedRoom),
|
||||||
|
map(action => {
|
||||||
|
return info({
|
||||||
|
roomSeq: action.roomSeq,
|
||||||
|
baseSeq: 0,
|
||||||
|
requestCount: 50
|
||||||
|
});
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
info$ = createEffect(
|
||||||
|
() => {
|
||||||
|
let infoList: Info[];
|
||||||
|
|
||||||
|
return this.actions$.pipe(
|
||||||
|
ofType(info),
|
||||||
|
tap(() => {
|
||||||
|
infoList = [];
|
||||||
|
}),
|
||||||
|
switchMap(req => {
|
||||||
|
return this.eventProtocolService.info(req).pipe(
|
||||||
|
map(res => {
|
||||||
|
switch (res.Type) {
|
||||||
|
case SSVC_TYPE_EVENT_INFO_DATA:
|
||||||
|
infoList.push(...(res as InfoData).infoList);
|
||||||
|
break;
|
||||||
|
case SSVC_TYPE_EVENT_INFO_RES:
|
||||||
|
this.store.dispatch(
|
||||||
|
infoSuccess({
|
||||||
|
infoList,
|
||||||
|
res: res as InfoResponse
|
||||||
|
})
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
catchError(error => of(infoFailure({ error })))
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{ dispatch: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private actions$: Actions,
|
||||||
|
private store: Store<any>,
|
||||||
|
private eventProtocolService: EventProtocolService,
|
||||||
|
private sessionStorageService: SessionStorageService,
|
||||||
|
private logger: NGXLogger
|
||||||
|
) {}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
export * from './actions';
|
||||||
|
export * from './effects';
|
||||||
|
export * from './reducers';
|
||||||
|
export * from './state';
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { createReducer, on } from '@ngrx/store';
|
||||||
|
import { initialState } from './state';
|
||||||
|
import { infoSuccess } from './actions';
|
||||||
|
|
||||||
|
export const reducer = createReducer(
|
||||||
|
initialState,
|
||||||
|
on(infoSuccess, (state, action) => {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
infoList: action.infoList,
|
||||||
|
infoStatus: action.res
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { Selector, createSelector } from '@ngrx/store';
|
||||||
|
import { InfoResponse, Info } from '@ucap-webmessenger/protocol-event';
|
||||||
|
|
||||||
|
export interface State {
|
||||||
|
infoList: Info[] | null;
|
||||||
|
infoStatus: InfoResponse | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const initialState: State = {
|
||||||
|
infoList: null,
|
||||||
|
infoStatus: null
|
||||||
|
};
|
||||||
|
|
||||||
|
export function selectors<S>(selector: Selector<any, State>) {
|
||||||
|
return {
|
||||||
|
infoList: createSelector(
|
||||||
|
selector,
|
||||||
|
(state: State) => state.infoList
|
||||||
|
),
|
||||||
|
infoStatus: createSelector(
|
||||||
|
selector,
|
||||||
|
(state: State) => state.infoStatus
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ import { Type } from '@angular/core';
|
||||||
import { Action, combineReducers, Selector, createSelector } from '@ngrx/store';
|
import { Action, combineReducers, Selector, createSelector } from '@ngrx/store';
|
||||||
|
|
||||||
import * as ChatStore from './chat';
|
import * as ChatStore from './chat';
|
||||||
|
import * as EventStore from './event';
|
||||||
import * as OptionStore from './option';
|
import * as OptionStore from './option';
|
||||||
import * as QueryStore from './query';
|
import * as QueryStore from './query';
|
||||||
import * as RoomStore from './room';
|
import * as RoomStore from './room';
|
||||||
|
@ -10,6 +11,7 @@ import * as SyncStore from './sync';
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
chat: ChatStore.State;
|
chat: ChatStore.State;
|
||||||
|
event: EventStore.State;
|
||||||
option: OptionStore.State;
|
option: OptionStore.State;
|
||||||
query: QueryStore.State;
|
query: QueryStore.State;
|
||||||
room: RoomStore.State;
|
room: RoomStore.State;
|
||||||
|
@ -19,6 +21,7 @@ export interface State {
|
||||||
|
|
||||||
export const effects: Type<any>[] = [
|
export const effects: Type<any>[] = [
|
||||||
ChatStore.Effects,
|
ChatStore.Effects,
|
||||||
|
EventStore.Effects,
|
||||||
OptionStore.Effects,
|
OptionStore.Effects,
|
||||||
QueryStore.Effects,
|
QueryStore.Effects,
|
||||||
RoomStore.Effects,
|
RoomStore.Effects,
|
||||||
|
@ -29,6 +32,7 @@ export const effects: Type<any>[] = [
|
||||||
export function reducers(state: State | undefined, action: Action) {
|
export function reducers(state: State | undefined, action: Action) {
|
||||||
return combineReducers({
|
return combineReducers({
|
||||||
chat: ChatStore.reducer,
|
chat: ChatStore.reducer,
|
||||||
|
event: EventStore.reducer,
|
||||||
option: OptionStore.reducer,
|
option: OptionStore.reducer,
|
||||||
query: QueryStore.reducer,
|
query: QueryStore.reducer,
|
||||||
room: RoomStore.reducer,
|
room: RoomStore.reducer,
|
||||||
|
@ -45,6 +49,12 @@ export function selectors<S>(selector: Selector<any, State>) {
|
||||||
(state: State) => state.chat
|
(state: State) => state.chat
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
EventSelector: EventStore.selectors(
|
||||||
|
createSelector(
|
||||||
|
selector,
|
||||||
|
(state: State) => state.event
|
||||||
|
)
|
||||||
|
),
|
||||||
OptionSelector: OptionStore.selectors(
|
OptionSelector: OptionStore.selectors(
|
||||||
createSelector(
|
createSelector(
|
||||||
selector,
|
selector,
|
||||||
|
|
|
@ -6,7 +6,8 @@ import {
|
||||||
ProtocolDecoder,
|
ProtocolDecoder,
|
||||||
ProtocolMessage,
|
ProtocolMessage,
|
||||||
ProtocolStream,
|
ProtocolStream,
|
||||||
PacketBodyValue
|
PacketBodyValue,
|
||||||
|
BodyStringDivider
|
||||||
} from '@ucap-webmessenger/protocol';
|
} from '@ucap-webmessenger/protocol';
|
||||||
import { EventType } from '../types/event.type';
|
import { EventType } from '../types/event.type';
|
||||||
import { Info } from '../models/info';
|
import { Info } from '../models/info';
|
||||||
|
@ -53,15 +54,19 @@ export const decodeInfoData: ProtocolDecoder<InfoData> = (
|
||||||
message: ProtocolMessage
|
message: ProtocolMessage
|
||||||
) => {
|
) => {
|
||||||
const infoList: Info[] = [];
|
const infoList: Info[] = [];
|
||||||
for (let i = 1; i < message.bodyList.length; ) {
|
|
||||||
infoList.push({
|
for (const body of message.bodyList) {
|
||||||
seq: message.bodyList[0],
|
const info = body.split(BodyStringDivider);
|
||||||
type: message.bodyList[1],
|
if (info.length > 5) {
|
||||||
senderSeq: message.bodyList[2],
|
infoList.push({
|
||||||
sendDate: message.bodyList[3],
|
seq: info[0],
|
||||||
sentMessage: message.bodyList[4],
|
type: info[1] as EventType,
|
||||||
receiverCount: message.bodyList[5]
|
senderSeq: info[2],
|
||||||
});
|
sendDate: info[3],
|
||||||
|
sentMessage: info[4],
|
||||||
|
receiverCount: info[5]
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
PacketBodyValue
|
PacketBodyValue
|
||||||
} from '@ucap-webmessenger/protocol';
|
} from '@ucap-webmessenger/protocol';
|
||||||
import { EventType } from '../types/event.type';
|
import { EventType } from '../types/event.type';
|
||||||
import { PushClType } from '../types/pushCl.type';
|
import { PushClType } from '../types/push-cl.type';
|
||||||
|
|
||||||
export interface PushRequest extends ProtocolRequest {
|
export interface PushRequest extends ProtocolRequest {
|
||||||
// 대화방SEQ(s)
|
// 대화방SEQ(s)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
ProtocolNotification
|
ProtocolNotification
|
||||||
} from '@ucap-webmessenger/protocol';
|
} from '@ucap-webmessenger/protocol';
|
||||||
import { EventType } from '../types/event.type';
|
import { EventType } from '../types/event.type';
|
||||||
import { PushStatus } from '../types/pushStatus.type';
|
import { PushStatus } from '../types/push-status.type';
|
||||||
|
|
||||||
export interface SendRequest extends ProtocolRequest {
|
export interface SendRequest extends ProtocolRequest {
|
||||||
// 0. 대화방SEQ(s)
|
// 0. 대화방SEQ(s)
|
||||||
|
|
|
@ -12,3 +12,6 @@ export * from './lib/services/event-protocol.service';
|
||||||
export * from './lib/ucap-event-protocol.module';
|
export * from './lib/ucap-event-protocol.module';
|
||||||
|
|
||||||
export * from './lib/types/event.type';
|
export * from './lib/types/event.type';
|
||||||
|
export * from './lib/types/push-cl.type';
|
||||||
|
export * from './lib/types/push-status.type';
|
||||||
|
export * from './lib/types/service';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user