2019-09-25 17:26:19 +09:00
|
|
|
import { Selector, createSelector } from '@ngrx/store';
|
2019-10-11 11:58:03 +09:00
|
|
|
import { EntityState, createEntityAdapter } from '@ngrx/entity';
|
|
|
|
import {
|
|
|
|
UserInfo,
|
|
|
|
GroupDetailData,
|
|
|
|
RoomUserData,
|
|
|
|
RoomUserDetailData
|
|
|
|
} from '@ucap-webmessenger/protocol-sync';
|
2019-10-02 15:49:25 +09:00
|
|
|
import {
|
|
|
|
RoomInfo,
|
|
|
|
UserInfo as RoomUserInfo
|
|
|
|
} from '@ucap-webmessenger/protocol-room';
|
2019-09-25 17:26:19 +09:00
|
|
|
|
2019-10-11 11:58:03 +09:00
|
|
|
export interface Buddy2State extends EntityState<UserInfo> {
|
|
|
|
syncDate: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Group2State extends EntityState<GroupDetailData> {
|
|
|
|
syncDate: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RoomState extends EntityState<RoomInfo> {
|
|
|
|
syncDate: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RoomUserState extends EntityState<RoomUserDetailData> {}
|
|
|
|
|
|
|
|
export interface RoomUserShortState extends EntityState<RoomUserData> {}
|
|
|
|
|
2019-09-25 17:26:19 +09:00
|
|
|
export interface State {
|
2019-10-11 11:58:03 +09:00
|
|
|
buddy2: Buddy2State;
|
|
|
|
group2: Group2State;
|
|
|
|
room: RoomState;
|
|
|
|
roomUser: RoomUserState;
|
|
|
|
roomUserShort: RoomUserShortState;
|
2019-10-17 15:06:38 +09:00
|
|
|
chatUnreadCount: number;
|
2019-09-25 17:26:19 +09:00
|
|
|
}
|
|
|
|
|
2019-10-11 11:58:03 +09:00
|
|
|
export const adapterBuddy2 = createEntityAdapter<UserInfo>({
|
|
|
|
selectId: userInfo => userInfo.seq
|
|
|
|
});
|
|
|
|
export const adapterGroup2 = createEntityAdapter<GroupDetailData>({
|
|
|
|
selectId: groupDetailData => groupDetailData.seq,
|
|
|
|
sortComparer: (a, b) => {
|
|
|
|
// 기본그룹은 제일 하단
|
|
|
|
if (0 === a.seq) {
|
|
|
|
return 1;
|
|
|
|
} else if (0 === b.seq) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (b.name > a.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
export const adapterRoom = createEntityAdapter<RoomInfo>({
|
|
|
|
selectId: roomInfo => roomInfo.roomSeq,
|
|
|
|
sortComparer: (a, b) => {
|
|
|
|
return (
|
|
|
|
new Date(b.finalEventDate).getTime() -
|
|
|
|
new Date(a.finalEventDate).getTime()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
export const adapterRoomUser = createEntityAdapter<RoomUserDetailData>({
|
|
|
|
selectId: roomUserDetailData => roomUserDetailData.roomSeq
|
|
|
|
});
|
|
|
|
export const adapterRoomUserShort = createEntityAdapter<RoomUserData>({
|
|
|
|
selectId: roomUserData => roomUserData.roomSeq
|
|
|
|
});
|
|
|
|
|
|
|
|
const buddy2InitialState: Buddy2State = adapterBuddy2.getInitialState({
|
|
|
|
syncDate: ''
|
|
|
|
});
|
|
|
|
const group2InitialState: Group2State = adapterGroup2.getInitialState({
|
|
|
|
syncDate: ''
|
|
|
|
});
|
|
|
|
const roomInitialState: RoomState = adapterRoom.getInitialState({
|
|
|
|
syncDate: ''
|
|
|
|
});
|
|
|
|
const roomUserInitialState: RoomUserState = adapterRoomUser.getInitialState({});
|
|
|
|
const roomUserShortInitialState: RoomUserShortState = adapterRoomUserShort.getInitialState(
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
2019-09-25 17:26:19 +09:00
|
|
|
export const initialState: State = {
|
2019-10-11 11:58:03 +09:00
|
|
|
buddy2: buddy2InitialState,
|
|
|
|
group2: group2InitialState,
|
|
|
|
room: roomInitialState,
|
|
|
|
roomUser: roomUserInitialState,
|
2019-10-17 15:06:38 +09:00
|
|
|
roomUserShort: roomUserShortInitialState,
|
|
|
|
chatUnreadCount: 0
|
2019-09-25 17:26:19 +09:00
|
|
|
};
|
|
|
|
|
2019-10-11 11:58:03 +09:00
|
|
|
const {
|
|
|
|
selectAll: ngeSelectAllBuddy2,
|
|
|
|
selectEntities: ngeSelectEntitiesBuddy2,
|
|
|
|
selectIds: ngeSelectIdsBuddy2,
|
|
|
|
selectTotal: ngeSelectTotalBuddy2
|
|
|
|
} = adapterBuddy2.getSelectors();
|
|
|
|
|
|
|
|
const {
|
|
|
|
selectAll: ngeSelectAllGroup2,
|
|
|
|
selectEntities: ngeSelectEntitiesGroup2,
|
|
|
|
selectIds: ngeSelectIdsGroup2,
|
|
|
|
selectTotal: ngeSelectTotalGroup2
|
|
|
|
} = adapterGroup2.getSelectors();
|
|
|
|
|
|
|
|
const {
|
|
|
|
selectAll: ngeSelectAllRoom,
|
|
|
|
selectEntities: ngeSelectEntitiesRoom,
|
|
|
|
selectIds: ngeSelectIdsRoom,
|
|
|
|
selectTotal: ngeSelectTotalRoom
|
|
|
|
} = adapterRoom.getSelectors();
|
|
|
|
|
|
|
|
const {
|
|
|
|
selectAll: ngeSelectAllRoomUser,
|
|
|
|
selectEntities: ngeSelectEntitiesRoomUser,
|
|
|
|
selectIds: ngeSelectIdsRoomUser,
|
|
|
|
selectTotal: ngeSelectTotalRoomUser
|
|
|
|
} = adapterRoomUser.getSelectors();
|
|
|
|
|
|
|
|
const {
|
|
|
|
selectAll: ngeSelectAllRoomUserShort,
|
|
|
|
selectEntities: ngeSelectEntitiesRoomUserShort,
|
|
|
|
selectIds: ngeSelectIdsRoomUserShort,
|
|
|
|
selectTotal: ngeSelectTotalRoomUserShort
|
|
|
|
} = adapterRoomUserShort.getSelectors();
|
|
|
|
|
2019-09-25 17:26:19 +09:00
|
|
|
export function selectors<S>(selector: Selector<any, State>) {
|
2019-10-11 11:58:03 +09:00
|
|
|
const selectBuddy2 = createSelector(
|
|
|
|
selector,
|
|
|
|
(state: State) => state.buddy2
|
|
|
|
);
|
|
|
|
|
|
|
|
const selectGroup2 = createSelector(
|
|
|
|
selector,
|
|
|
|
(state: State) => state.group2
|
|
|
|
);
|
|
|
|
|
|
|
|
const selectRoom = createSelector(
|
|
|
|
selector,
|
|
|
|
(state: State) => state.room
|
|
|
|
);
|
|
|
|
|
|
|
|
const selectRoomUser = createSelector(
|
|
|
|
selector,
|
|
|
|
(state: State) => state.roomUser
|
|
|
|
);
|
|
|
|
|
|
|
|
const selectRoomUserShort = createSelector(
|
|
|
|
selector,
|
|
|
|
(state: State) => state.roomUserShort
|
|
|
|
);
|
|
|
|
|
2019-09-25 17:26:19 +09:00
|
|
|
return {
|
2019-10-11 11:58:03 +09:00
|
|
|
selectAllBuddy2: createSelector(
|
|
|
|
selectBuddy2,
|
|
|
|
ngeSelectAllBuddy2
|
2019-09-25 18:08:50 +09:00
|
|
|
),
|
2019-10-11 11:58:03 +09:00
|
|
|
selectBuddy2SyncDate: createSelector(
|
|
|
|
selectBuddy2,
|
|
|
|
buddy2State => buddy2State.syncDate
|
2019-09-25 18:08:50 +09:00
|
|
|
),
|
2019-10-11 11:58:03 +09:00
|
|
|
selectAllGroup2: createSelector(
|
|
|
|
selectGroup2,
|
|
|
|
ngeSelectAllGroup2
|
2019-09-25 18:08:50 +09:00
|
|
|
),
|
2019-10-11 11:58:03 +09:00
|
|
|
selectGroup2SyncDate: createSelector(
|
|
|
|
selectGroup2,
|
|
|
|
group2State => group2State.syncDate
|
2019-09-27 12:53:21 +09:00
|
|
|
),
|
2019-10-11 11:58:03 +09:00
|
|
|
selectAllRoom: createSelector(
|
|
|
|
selectRoom,
|
|
|
|
ngeSelectAllRoom
|
2019-10-02 15:49:25 +09:00
|
|
|
),
|
2019-10-11 11:58:03 +09:00
|
|
|
selectRoomSyncDate: createSelector(
|
|
|
|
selectRoom,
|
|
|
|
roomState => roomState.syncDate
|
|
|
|
),
|
|
|
|
selectAllRoomUser: createSelector(
|
|
|
|
selectRoomUser,
|
|
|
|
ngeSelectAllRoomUser
|
2019-10-02 15:49:25 +09:00
|
|
|
),
|
2019-10-11 11:58:03 +09:00
|
|
|
selectAllRoomUserShort: createSelector(
|
|
|
|
selectRoomUserShort,
|
|
|
|
ngeSelectAllRoomUserShort
|
2019-10-17 15:06:38 +09:00
|
|
|
),
|
|
|
|
selectChatUnreadCount: createSelector(
|
|
|
|
selector,
|
|
|
|
(state: State) => state.chatUnreadCount
|
2019-09-25 17:26:19 +09:00
|
|
|
)
|
|
|
|
};
|
|
|
|
}
|