diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/chat/actions.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/chat/actions.ts index ac7f6f1a..6d1196ef 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/chat/actions.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/chat/actions.ts @@ -21,6 +21,8 @@ export const clearSelectedRoom = createAction( '[Messenger::Chat] clearSelectedRoom' ); +export const clearEvent = createAction('[Messenger::Room] Clear Event'); + export const newEventMessage = createAction( '[Messenger::Chat] newEventMessage', props<{ diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts index 893992de..c24d7474 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/event/reducers.ts @@ -144,7 +144,7 @@ export const reducer = createReducer( }; }), - on(ChatStore.selectedRoom, (state, action) => { + on(ChatStore.clearEvent, (state, action) => { return { ...initialState }; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/room/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/room/effects.ts index 3f7e14ae..e48f746e 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/room/effects.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/room/effects.ts @@ -76,20 +76,35 @@ import { LoginInfo, KEY_LOGIN_INFO } from '@app/types'; @Injectable() export class Effects { - selectedRoomForInfo$ = createEffect(() => - this.actions$.pipe( - ofType(ChatStore.selectedRoom), - map(action => { - const loginInfo = this.sessionStorageService.get( - KEY_LOGIN_INFO - ); - return info({ - roomSeq: action.roomSeq, - isDetail: true, - localeCode: loginInfo.localeCode - }); - }) - ) + selectedRoomForInfo$ = createEffect( + () => { + return this.actions$.pipe( + ofType(ChatStore.selectedRoom), + withLatestFrom( + this.store.pipe( + select((state: any) => state.messenger.room.roomInfo as RoomInfo) + ) + ), + map(([action, roomInfo]) => { + if (!!roomInfo && roomInfo.roomSeq === action.roomSeq) { + } else { + this.store.dispatch(ChatStore.clearEvent()); + + const loginInfo = this.sessionStorageService.get( + KEY_LOGIN_INFO + ); + this.store.dispatch( + info({ + roomSeq: action.roomSeq, + isDetail: true, + localeCode: loginInfo.localeCode + }) + ); + } + }) + ); + }, + { dispatch: false } ); info$ = createEffect(