82 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-10-08 13:18:05 +09:00
import { createReducer, on } from '@ngrx/store';
import { initialState, adapterInfoList } from './state';
import {
infoSuccess,
appendInfoList,
info,
infoFailure,
recallInfoList
} from './actions';
2019-10-11 13:11:48 +09:00
import * as AuthenticationStore from '@app/store/account/authentication';
import { Info, EventType } from '@ucap-webmessenger/protocol-event';
2019-10-08 13:18:05 +09:00
export const reducer = createReducer(
initialState,
2019-10-08 15:25:00 +09:00
on(info, (state, action) => {
return {
...state,
infoListProcessing: true
};
}),
2019-10-08 13:18:05 +09:00
on(infoSuccess, (state, action) => {
return {
...state,
infoList: adapterInfoList.addAll(action.infoList, {
...state.infoList
}),
2019-10-08 15:25:00 +09:00
infoStatus: action.res,
infoListProcessing: false
};
}),
on(infoFailure, (state, action) => {
return {
...state,
infoListProcessing: false
2019-10-08 13:18:05 +09:00
};
2019-10-08 14:59:22 +09:00
}),
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: '회수된 메시지'
};
2019-10-08 14:59:22 +09:00
return {
...state,
infoList: adapterInfoList.updateOne(
{ id: eventSeq, changes: statusEventInfo },
{ ...state.infoList }
)
2019-10-08 14:59:22 +09:00
};
2019-10-11 13:11:48 +09:00
}),
on(AuthenticationStore.logout, (state, action) => {
return {
...initialState
};
2019-10-08 13:18:05 +09:00
})
);