2019-09-25 17:26:19 +09:00
|
|
|
import { createReducer, on } from '@ngrx/store';
|
2019-10-11 11:58:03 +09:00
|
|
|
import {
|
|
|
|
initialState,
|
|
|
|
adapterBuddy2,
|
|
|
|
adapterGroup2,
|
|
|
|
adapterRoom,
|
|
|
|
adapterRoomUser,
|
|
|
|
adapterRoomUserShort
|
|
|
|
} from './state';
|
2019-10-10 15:44:39 +09:00
|
|
|
import {
|
|
|
|
buddy2Success,
|
|
|
|
group2Success,
|
|
|
|
roomSuccess,
|
|
|
|
updateRoomForNewEventMessage
|
|
|
|
} from './actions';
|
2019-10-11 11:58:03 +09:00
|
|
|
import {
|
|
|
|
RoomUserDetailData,
|
|
|
|
RoomUserData
|
|
|
|
} from '@ucap-webmessenger/protocol-sync';
|
2019-10-10 14:50:58 +09:00
|
|
|
|
2019-09-25 17:26:19 +09:00
|
|
|
export const reducer = createReducer(
|
|
|
|
initialState,
|
|
|
|
on(buddy2Success, (state, action) => {
|
|
|
|
return {
|
|
|
|
...state,
|
2019-10-11 11:58:03 +09:00
|
|
|
buddy2: adapterBuddy2.addAll(action.buddyList, {
|
|
|
|
...state.buddy2,
|
|
|
|
syncDate: 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-11 11:58:03 +09:00
|
|
|
group2: adapterGroup2.addAll(action.groupList, {
|
|
|
|
...state.group2,
|
|
|
|
syncDate: action.syncDate
|
|
|
|
})
|
2019-09-25 18:08:50 +09:00
|
|
|
};
|
2019-10-02 15:49:25 +09:00
|
|
|
}),
|
|
|
|
|
|
|
|
on(roomSuccess, (state, action) => {
|
2019-10-11 11:58:03 +09:00
|
|
|
const roomUserList: RoomUserDetailData[] = [];
|
|
|
|
const roomUserShortList: RoomUserData[] = [];
|
|
|
|
|
|
|
|
for (const key in action.roomUserInfoMap) {
|
|
|
|
if (action.roomUserInfoMap.hasOwnProperty(key)) {
|
|
|
|
const element = action.roomUserInfoMap[key];
|
|
|
|
if (!!element.userInfoList && 0 < element.userInfoList.length) {
|
|
|
|
roomUserList.push({ roomSeq: key, userInfos: element.userInfoList });
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
!!element.userInfoShortList &&
|
|
|
|
0 < element.userInfoShortList.length
|
|
|
|
) {
|
|
|
|
roomUserShortList.push({
|
|
|
|
roomSeq: key,
|
|
|
|
userInfos: element.userInfoShortList
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-02 15:49:25 +09:00
|
|
|
return {
|
|
|
|
...state,
|
2019-10-11 11:58:03 +09:00
|
|
|
room: adapterRoom.addAll(action.roomList, {
|
|
|
|
...state.room,
|
|
|
|
syncDate: action.syncDate
|
|
|
|
}),
|
|
|
|
roomUser: adapterRoomUser.addAll(roomUserList, {
|
|
|
|
...state.roomUser
|
|
|
|
}),
|
|
|
|
roomUserShort: adapterRoomUserShort.addAll(roomUserShortList, {
|
|
|
|
...state.roomUserShort
|
|
|
|
})
|
2019-10-02 15:49:25 +09:00
|
|
|
};
|
2019-10-10 14:50:58 +09:00
|
|
|
}),
|
|
|
|
|
2019-10-10 15:44:39 +09:00
|
|
|
on(updateRoomForNewEventMessage, (state, action) => {
|
2019-10-11 11:58:03 +09:00
|
|
|
const roomInfo = {
|
|
|
|
...state.room.entities[action.roomSeq],
|
|
|
|
finalEventDate: action.info.sendDate,
|
|
|
|
finalEventMessage: action.info.sentMessage
|
|
|
|
};
|
2019-10-10 14:50:58 +09:00
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
2019-10-11 11:58:03 +09:00
|
|
|
room: adapterRoom.updateOne(
|
|
|
|
{ id: action.roomSeq, changes: roomInfo },
|
|
|
|
{ ...state.room }
|
|
|
|
)
|
2019-10-10 14:50:58 +09:00
|
|
|
};
|
2019-09-25 17:26:19 +09:00
|
|
|
})
|
|
|
|
);
|