next-ucap-messenger/projects/ucap-webmessenger-app/src/app/store/messenger/status/reducers.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-10-02 09:09:39 +00:00
import { createReducer, on } from '@ngrx/store';
2019-10-11 07:40:55 +00:00
import { initialState, State, adapterStatusBulkInfo } from './state';
import { bulkInfoSuccess, statusNotification } from './actions';
2019-10-02 09:09:39 +00:00
2019-10-11 04:11:48 +00:00
import * as AuthenticationStore from '@app/store/account/authentication';
2019-10-11 07:40:55 +00:00
import { StatusBulkInfo } from '@ucap-webmessenger/protocol-status';
2019-10-11 04:11:48 +00:00
2019-10-02 09:09:39 +00:00
export const reducer = createReducer(
initialState,
on(bulkInfoSuccess, (state, action) => {
return {
...state,
2019-10-11 07:40:55 +00:00
statusBulkInfo: adapterStatusBulkInfo.addAll(action.statusBulkInfoList, {
...state.statusBulkInfo
})
} as State;
}),
on(statusNotification, (state, action) => {
const noti = action.noti;
const statusBulkInfoState: StatusBulkInfo = {
...state.statusBulkInfo.entities[noti.userSeq],
conferenceStatus: noti.conferenceStatus,
imessengerStatus: noti.imessengerStatus,
mobileConferenceStatus: noti.mobileConferenceStatus,
mobileStatus: noti.mobileStatus,
pcStatus: noti.pcStatus,
phoneStatus: noti.phoneStatus,
statusMessage: noti.statusMessage
};
return {
...state,
statusBulkInfo: adapterStatusBulkInfo.updateOne(
{ id: noti.userSeq, changes: statusBulkInfoState },
{ ...state.statusBulkInfo }
)
2019-10-02 09:09:39 +00:00
};
2019-10-11 04:11:48 +00:00
}),
on(AuthenticationStore.logout, (state, action) => {
return {
...initialState
};
2019-10-02 09:09:39 +00:00
})
);