event message sync is modified
This commit is contained in:
parent
150ebd56af
commit
df1d9bea28
|
@ -12,6 +12,7 @@ import {
|
|||
UserInfoShort,
|
||||
UserInfo as RoomUserInfo
|
||||
} from '@ucap-webmessenger/protocol-room';
|
||||
import { Info } from '@ucap-webmessenger/protocol-event';
|
||||
|
||||
export const buddy2 = createAction(
|
||||
'[Messenger::Sync] Buddy2',
|
||||
|
@ -66,3 +67,11 @@ export const roomFailure = createAction(
|
|||
'[Messenger::Sync] Room Failure',
|
||||
props<{ error: any }>()
|
||||
);
|
||||
|
||||
export const updateRoomForNewEventMessage = createAction(
|
||||
'[Messenger::Sync] updateRoomForNewEventMessage',
|
||||
props<{
|
||||
roomSeq: string;
|
||||
info: Info;
|
||||
}>()
|
||||
);
|
||||
|
|
|
@ -25,7 +25,8 @@ import {
|
|||
group2Failure,
|
||||
room,
|
||||
roomFailure,
|
||||
roomSuccess
|
||||
roomSuccess,
|
||||
updateRoomForNewEventMessage
|
||||
} from './actions';
|
||||
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
|
||||
|
||||
|
@ -57,6 +58,8 @@ import {
|
|||
} from '@ucap-webmessenger/protocol-room';
|
||||
import { LoginInfo, KEY_LOGIN_INFO } from '@app/types';
|
||||
|
||||
import * as ChatStore from '@app/store/messenger/chat';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
buddy2$ = createEffect(
|
||||
|
@ -199,6 +202,43 @@ export class Effects {
|
|||
{ dispatch: false }
|
||||
);
|
||||
|
||||
newEventMessageForRoomInfoList$ = createEffect(
|
||||
() =>
|
||||
this.actions$.pipe(
|
||||
ofType(ChatStore.newEventMessage),
|
||||
withLatestFrom(
|
||||
this.store.pipe(
|
||||
select((state: any) => state.messenger.sync.roomList as RoomInfo[])
|
||||
),
|
||||
this.store.pipe(
|
||||
select((state: any) => state.messenger.sync.roomSyncDate as string)
|
||||
)
|
||||
),
|
||||
tap(([action, roomList, roomSyncDate]) => {
|
||||
const index = roomList.findIndex(
|
||||
(roomInfo, i) => roomInfo.roomSeq === action.roomSeq
|
||||
);
|
||||
|
||||
if (-1 === index) {
|
||||
const loginInfo = this.sessionStorageService.get<LoginInfo>(
|
||||
KEY_LOGIN_INFO
|
||||
);
|
||||
|
||||
this.store.dispatch(
|
||||
room({
|
||||
syncDate: roomSyncDate,
|
||||
localeCode: loginInfo.localeCode
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
this.store.dispatch(updateRoomForNewEventMessage(action));
|
||||
})
|
||||
),
|
||||
{ dispatch: false }
|
||||
);
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private store: Store<any>,
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import { createReducer, on } from '@ngrx/store';
|
||||
import { initialState } from './state';
|
||||
import { buddy2Success, group2Success, roomSuccess } from './actions';
|
||||
import {
|
||||
buddy2Success,
|
||||
group2Success,
|
||||
roomSuccess,
|
||||
updateRoomForNewEventMessage
|
||||
} from './actions';
|
||||
|
||||
import * as ChatStore from '@app/store/messenger/chat';
|
||||
import { RoomInfo } from '@ucap-webmessenger/protocol-room';
|
||||
|
||||
export const reducer = createReducer(
|
||||
|
@ -10,7 +14,7 @@ export const reducer = createReducer(
|
|||
on(buddy2Success, (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
buddyInfoList: action.buddyList,
|
||||
buddyInfoList: [...state.buddyInfoList, ...action.buddyList],
|
||||
buddy2SyncDate: action.syncDate
|
||||
};
|
||||
}),
|
||||
|
@ -18,7 +22,7 @@ export const reducer = createReducer(
|
|||
on(group2Success, (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
groupList: action.groupList,
|
||||
groupList: [...state.groupList, ...action.groupList],
|
||||
group2SyncDate: action.syncDate
|
||||
};
|
||||
}),
|
||||
|
@ -26,13 +30,16 @@ export const reducer = createReducer(
|
|||
on(roomSuccess, (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
roomList: action.roomList,
|
||||
roomUserInfoMap: action.roomUserInfoMap,
|
||||
roomList: [...state.roomList, ...action.roomList],
|
||||
roomUserInfoMap: {
|
||||
...state.roomUserInfoMap,
|
||||
...action.roomUserInfoMap
|
||||
},
|
||||
roomSyncDate: action.syncDate
|
||||
};
|
||||
}),
|
||||
|
||||
on(ChatStore.newEventMessage, (state, action) => {
|
||||
on(updateRoomForNewEventMessage, (state, action) => {
|
||||
const roomList: RoomInfo[] = [];
|
||||
|
||||
state.roomList.forEach((roomInfo, index) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user