55 lines
1.2 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-02 15:49:25 +09:00
import { buddy2Success, group2Success, roomSuccess } from './actions';
2019-09-25 17:26:19 +09:00
2019-10-10 14:50:58 +09:00
import * as ChatStore from '@app/store/messenger/chat';
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-02 14:34:17 +09:00
buddyInfoList: action.buddyList,
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-02 14:34:17 +09:00
groupList: action.groupList,
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,
roomList: action.roomList,
roomUserInfoMap: action.roomUserInfoMap,
roomSyncDate: action.syncDate
};
2019-10-10 14:50:58 +09:00
}),
on(ChatStore.newEventMessage, (state, action) => {
const roomList: RoomInfo[] = [];
state.roomList.forEach((roomInfo, index) => {
if (roomInfo.roomSeq === action.roomSeq) {
roomList.push({
...roomInfo,
finalEventMessage: action.info.sentMessage
});
} else {
roomList.push(roomInfo);
}
});
return {
...state,
roomList
};
2019-09-25 17:26:19 +09:00
})
);