import { createReducer, on } from '@ngrx/store'; import { initialState } from './state'; import { buddy2Success, group2Success, roomSuccess, updateRoomForNewEventMessage } from './actions'; import { RoomInfo } from '@ucap-webmessenger/protocol-room'; export const reducer = createReducer( initialState, on(buddy2Success, (state, action) => { return { ...state, buddyInfoList: [...state.buddyInfoList, ...action.buddyList], buddy2SyncDate: action.syncDate }; }), on(group2Success, (state, action) => { return { ...state, groupList: [...state.groupList, ...action.groupList], group2SyncDate: action.syncDate }; }), on(roomSuccess, (state, action) => { return { ...state, roomList: [...state.roomList, ...action.roomList], roomUserInfoMap: { ...state.roomUserInfoMap, ...action.roomUserInfoMap }, roomSyncDate: action.syncDate }; }), on(updateRoomForNewEventMessage, (state, action) => { const roomList: RoomInfo[] = []; state.roomList.forEach((roomInfo, index) => { if (roomInfo.roomSeq === action.roomSeq) { roomList.push({ ...roomInfo, finalEventDate: action.info.sendDate, finalEventMessage: action.info.sentMessage }); } else { roomList.push(roomInfo); } }); return { ...state, roomList }; }) );