effect for room sync is implemented
This commit is contained in:
parent
7c54e6606e
commit
a201536b02
|
@ -4,8 +4,14 @@ import {
|
|||
GroupRequest,
|
||||
GroupDetailData,
|
||||
GroupResponse,
|
||||
UserInfo
|
||||
UserInfo,
|
||||
RoomRequest
|
||||
} from '@ucap-webmessenger/protocol-sync';
|
||||
import {
|
||||
RoomInfo,
|
||||
UserInfoShort,
|
||||
UserInfo as RoomUserInfo
|
||||
} from '@ucap-webmessenger/protocol-room';
|
||||
|
||||
export const buddy2 = createAction(
|
||||
'[Messenger::Sync] Buddy2',
|
||||
|
@ -36,3 +42,27 @@ export const group2Failure = createAction(
|
|||
'[Messenger::Sync] Group2 Failure',
|
||||
props<{ error: any }>()
|
||||
);
|
||||
|
||||
export const room = createAction(
|
||||
'[Messenger::Sync] Room',
|
||||
props<RoomRequest>()
|
||||
);
|
||||
|
||||
export const roomSuccess = createAction(
|
||||
'[Messenger::Sync] Room Success',
|
||||
props<{
|
||||
roomList: RoomInfo[];
|
||||
roomUserInfoMap: {
|
||||
[param: string]: {
|
||||
userInfoShortList: UserInfoShort[];
|
||||
userInfoList: RoomUserInfo[];
|
||||
};
|
||||
};
|
||||
syncDate: string;
|
||||
}>()
|
||||
);
|
||||
|
||||
export const roomFailure = createAction(
|
||||
'[Messenger::Sync] Room Failure',
|
||||
props<{ error: any }>()
|
||||
);
|
||||
|
|
|
@ -22,7 +22,10 @@ import {
|
|||
buddy2Failure,
|
||||
group2,
|
||||
group2Success,
|
||||
group2Failure
|
||||
group2Failure,
|
||||
room,
|
||||
roomFailure,
|
||||
roomSuccess
|
||||
} from './actions';
|
||||
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
||||
|
||||
|
@ -36,9 +39,23 @@ import {
|
|||
GroupResponse,
|
||||
UserInfo,
|
||||
SSVC_TYPE_SYNC_BUDDY2_RES,
|
||||
SSVC_TYPE_SYNC_GROUP_RES2
|
||||
SSVC_TYPE_SYNC_GROUP_RES2,
|
||||
SSVC_TYPE_SYNC_ROOM_DATA,
|
||||
SSVC_TYPE_SYNC_ROOM_USER,
|
||||
SSVC_TYPE_SYNC_ROOM_USER2,
|
||||
SSVC_TYPE_SYNC_ROOM_RES,
|
||||
RoomData,
|
||||
RoomUserData,
|
||||
RoomUserDetailData,
|
||||
RoomResponse
|
||||
} from '@ucap-webmessenger/protocol-sync';
|
||||
import { regViewSuccess } from '@app/store/setting/option';
|
||||
import {
|
||||
RoomInfo,
|
||||
UserInfoShort,
|
||||
UserInfo as RoomUserInfo
|
||||
} from '@ucap-webmessenger/protocol-room';
|
||||
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
@ -110,6 +127,107 @@ export class Effects {
|
|||
{ dispatch: false }
|
||||
);
|
||||
|
||||
buddy2SuccessPostRoom$ = createEffect(() =>
|
||||
this.actions$.pipe(
|
||||
ofType(buddy2Success),
|
||||
map(action => {
|
||||
const loginInfo = this.sessionStorageService.get<LoginInfo>(
|
||||
KEY_LOGIN_INFO
|
||||
);
|
||||
|
||||
return loginInfo.localeCode;
|
||||
}),
|
||||
withLatestFrom(
|
||||
this.store.pipe(
|
||||
select(state => {
|
||||
return state.messenger.sync.roomSyncDate as string;
|
||||
})
|
||||
)
|
||||
),
|
||||
map(([localeCode, roomSyncDate]) =>
|
||||
room({ syncDate: roomSyncDate, localeCode })
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
room$ = createEffect(
|
||||
() => {
|
||||
let roomList: RoomInfo[];
|
||||
let roomUserInfoMap: {
|
||||
[param: string]: {
|
||||
userInfoShortList: UserInfoShort[];
|
||||
userInfoList: RoomUserInfo[];
|
||||
};
|
||||
};
|
||||
|
||||
return this.actions$.pipe(
|
||||
ofType(room),
|
||||
tap(() => {
|
||||
roomList = [];
|
||||
roomUserInfoMap = {};
|
||||
}),
|
||||
switchMap(req => {
|
||||
return this.syncProtocolService.room(req).pipe(
|
||||
map(res => {
|
||||
switch (res.Type) {
|
||||
case SSVC_TYPE_SYNC_ROOM_DATA:
|
||||
roomList.push(...(res as RoomData).roomInfos);
|
||||
break;
|
||||
case SSVC_TYPE_SYNC_ROOM_USER:
|
||||
{
|
||||
const roomUserData = res as RoomUserData;
|
||||
if (!roomUserInfoMap[roomUserData.roomSeq]) {
|
||||
roomUserInfoMap[roomUserData.roomSeq] = {
|
||||
userInfoList: [],
|
||||
userInfoShortList: []
|
||||
};
|
||||
}
|
||||
roomUserInfoMap[
|
||||
roomUserData.roomSeq
|
||||
].userInfoShortList.push(...roomUserData.userInfos);
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_SYNC_ROOM_USER2:
|
||||
{
|
||||
const roomUserDetailData = res as RoomUserDetailData;
|
||||
if (!roomUserInfoMap[roomUserDetailData.roomSeq]) {
|
||||
roomUserInfoMap[roomUserDetailData.roomSeq] = {
|
||||
userInfoList: [],
|
||||
userInfoShortList: []
|
||||
};
|
||||
}
|
||||
roomUserInfoMap[
|
||||
roomUserDetailData.roomSeq
|
||||
].userInfoList.push(...roomUserDetailData.userInfos);
|
||||
}
|
||||
break;
|
||||
case SSVC_TYPE_SYNC_ROOM_RES:
|
||||
{
|
||||
this.logger.debug(
|
||||
'roomList',
|
||||
roomList,
|
||||
'roomUserInfoMap',
|
||||
roomUserInfoMap
|
||||
);
|
||||
this.store.dispatch(
|
||||
roomSuccess({
|
||||
roomList,
|
||||
roomUserInfoMap,
|
||||
syncDate: (res as RoomResponse).syncDate
|
||||
})
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}),
|
||||
catchError(error => of(roomFailure({ error })))
|
||||
);
|
||||
})
|
||||
);
|
||||
},
|
||||
{ dispatch: false }
|
||||
);
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private store: Store<any>,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { createReducer, on } from '@ngrx/store';
|
||||
import { initialState } from './state';
|
||||
import { buddy2Success, group2Success } from './actions';
|
||||
import { buddy2Success, group2Success, roomSuccess } from './actions';
|
||||
|
||||
export const reducer = createReducer(
|
||||
initialState,
|
||||
|
@ -18,5 +18,14 @@ export const reducer = createReducer(
|
|||
groupList: action.groupList,
|
||||
group2SyncDate: action.syncDate
|
||||
};
|
||||
}),
|
||||
|
||||
on(roomSuccess, (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
roomList: action.roomList,
|
||||
roomUserInfoMap: action.roomUserInfoMap,
|
||||
roomSyncDate: action.syncDate
|
||||
};
|
||||
})
|
||||
);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import { Selector, createSelector } from '@ngrx/store';
|
||||
import { UserInfo, GroupDetailData } from '@ucap-webmessenger/protocol-sync';
|
||||
import {
|
||||
RoomInfo,
|
||||
UserInfoShort,
|
||||
UserInfo as RoomUserInfo
|
||||
} from '@ucap-webmessenger/protocol-room';
|
||||
|
||||
export interface State {
|
||||
buddyInfoList: UserInfo[];
|
||||
|
@ -7,13 +12,25 @@ export interface State {
|
|||
|
||||
groupList: GroupDetailData[];
|
||||
group2SyncDate: string;
|
||||
|
||||
roomList: RoomInfo[];
|
||||
roomUserInfoMap: {
|
||||
[param: string]: {
|
||||
userInfoShortList: UserInfoShort[];
|
||||
userInfoList: RoomUserInfo[];
|
||||
};
|
||||
};
|
||||
roomSyncDate: string;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
buddyInfoList: [],
|
||||
buddy2SyncDate: '',
|
||||
groupList: [],
|
||||
group2SyncDate: ''
|
||||
group2SyncDate: '',
|
||||
roomList: [],
|
||||
roomUserInfoMap: {},
|
||||
roomSyncDate: ''
|
||||
};
|
||||
|
||||
export function selectors<S>(selector: Selector<any, State>) {
|
||||
|
@ -42,6 +59,14 @@ export function selectors<S>(selector: Selector<any, State>) {
|
|||
buddyList: state.buddyInfoList
|
||||
};
|
||||
}
|
||||
),
|
||||
roomList: createSelector(
|
||||
selector,
|
||||
(state: State) => state.roomList
|
||||
),
|
||||
roomSyncDate: createSelector(
|
||||
selector,
|
||||
(state: State) => state.roomSyncDate
|
||||
)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -70,8 +70,9 @@ export const decodeRoomData: ProtocolDecoder<RoomData> = (
|
|||
message: ProtocolMessage
|
||||
) => {
|
||||
const roomInfos: RoomInfo[] = [];
|
||||
if (message.bodyList.length > 1) {
|
||||
const info = message.bodyList[1].split(BodyStringDivider);
|
||||
|
||||
for (const body of message.bodyList) {
|
||||
const info = body.split(BodyStringDivider);
|
||||
if (info.length > 11) {
|
||||
roomInfos.push({
|
||||
roomSeq: info[0],
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
export * from './lib/models/buddy';
|
||||
export * from './lib/models/group';
|
||||
export * from './lib/models/room';
|
||||
|
||||
export * from './lib/services/sync-protocol.service';
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user