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