63 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-09-25 17:26:19 +09:00
import { createReducer, on } from '@ngrx/store';
import { initialState } from './state';
2019-10-10 15:44:39 +09:00
import {
buddy2Success,
group2Success,
roomSuccess,
updateRoomForNewEventMessage
} from './actions';
2019-09-25 17:26:19 +09:00
2019-10-10 14:50:58 +09:00
import { RoomInfo } from '@ucap-webmessenger/protocol-room';
2019-09-25 17:26:19 +09:00
export const reducer = createReducer(
initialState,
on(buddy2Success, (state, action) => {
return {
...state,
2019-10-10 15:44:39 +09:00
buddyInfoList: [...state.buddyInfoList, ...action.buddyList],
2019-10-02 14:34:17 +09:00
buddy2SyncDate: action.syncDate
2019-09-25 18:08:50 +09:00
};
}),
2019-10-02 14:34:17 +09:00
2019-09-25 18:08:50 +09:00
on(group2Success, (state, action) => {
return {
...state,
2019-10-10 15:44:39 +09:00
groupList: [...state.groupList, ...action.groupList],
2019-10-02 14:34:17 +09:00
group2SyncDate: action.syncDate
2019-09-25 18:08:50 +09:00
};
2019-10-02 15:49:25 +09:00
}),
on(roomSuccess, (state, action) => {
return {
...state,
2019-10-10 15:44:39 +09:00
roomList: [...state.roomList, ...action.roomList],
roomUserInfoMap: {
...state.roomUserInfoMap,
...action.roomUserInfoMap
},
2019-10-02 15:49:25 +09:00
roomSyncDate: action.syncDate
};
2019-10-10 14:50:58 +09:00
}),
2019-10-10 15:44:39 +09:00
on(updateRoomForNewEventMessage, (state, action) => {
2019-10-10 14:50:58 +09:00
const roomList: RoomInfo[] = [];
state.roomList.forEach((roomInfo, index) => {
if (roomInfo.roomSeq === action.roomSeq) {
roomList.push({
...roomInfo,
2019-10-10 15:02:56 +09:00
finalEventDate: action.info.sendDate,
2019-10-10 14:50:58 +09:00
finalEventMessage: action.info.sentMessage
});
} else {
roomList.push(roomInfo);
}
});
return {
...state,
roomList
};
2019-09-25 17:26:19 +09:00
})
);