55 lines
1.2 KiB
TypeScript
55 lines
1.2 KiB
TypeScript
import { createReducer, on } from '@ngrx/store';
|
|
import { initialState } from './state';
|
|
import { buddy2Success, group2Success, roomSuccess } from './actions';
|
|
|
|
import * as ChatStore from '@app/store/messenger/chat';
|
|
import { RoomInfo } from '@ucap-webmessenger/protocol-room';
|
|
|
|
export const reducer = createReducer(
|
|
initialState,
|
|
on(buddy2Success, (state, action) => {
|
|
return {
|
|
...state,
|
|
buddyInfoList: action.buddyList,
|
|
buddy2SyncDate: action.syncDate
|
|
};
|
|
}),
|
|
|
|
on(group2Success, (state, action) => {
|
|
return {
|
|
...state,
|
|
groupList: action.groupList,
|
|
group2SyncDate: action.syncDate
|
|
};
|
|
}),
|
|
|
|
on(roomSuccess, (state, action) => {
|
|
return {
|
|
...state,
|
|
roomList: action.roomList,
|
|
roomUserInfoMap: action.roomUserInfoMap,
|
|
roomSyncDate: action.syncDate
|
|
};
|
|
}),
|
|
|
|
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
|
|
};
|
|
})
|
|
);
|