leejh 7ec9d2356b 수정 :: event info state 를 entity 처리 하도록 수정.
기능 구현 :: 대화 회수시 현재 대화방의 event 회수 처리 할 수 있도록 수정.
2019-10-15 19:09:26 +09:00

82 lines
1.8 KiB
TypeScript

import { createReducer, on } from '@ngrx/store';
import { initialState, adapterInfoList } from './state';
import {
infoSuccess,
appendInfoList,
info,
infoFailure,
recallInfoList
} from './actions';
import * as AuthenticationStore from '@app/store/account/authentication';
import { Info, EventType } from '@ucap-webmessenger/protocol-event';
export const reducer = createReducer(
initialState,
on(info, (state, action) => {
return {
...state,
infoListProcessing: true
};
}),
on(infoSuccess, (state, action) => {
return {
...state,
infoList: adapterInfoList.addAll(action.infoList, {
...state.infoList
}),
infoStatus: action.res,
infoListProcessing: false
};
}),
on(infoFailure, (state, action) => {
return {
...state,
infoListProcessing: false
};
}),
on(appendInfoList, (state, action) => {
const eventinfo = action.info;
const statusEventInfo: Info = {
...state.infoList.entities[eventinfo.seq],
type: eventinfo.type,
senderSeq: eventinfo.senderSeq,
sendDate: eventinfo.sendDate,
sentMessage: eventinfo.sentMessage,
receiverCount: eventinfo.receiverCount
};
return {
...state,
infoList: adapterInfoList.upsertOne(eventinfo, { ...state.infoList })
};
}),
on(recallInfoList, (state, action) => {
const eventSeq = action.eventSeq;
const statusEventInfo: Info = {
...state.infoList.entities[eventSeq],
type: EventType.RecalledMessage,
sentMessage: '회수된 메시지'
};
return {
...state,
infoList: adapterInfoList.updateOne(
{ id: eventSeq, changes: statusEventInfo },
{ ...state.infoList }
)
};
}),
on(AuthenticationStore.logout, (state, action) => {
return {
...initialState
};
})
);