From 81866a23fb67724773061876152e92000e0ef176 Mon Sep 17 00:00:00 2001 From: leejinho Date: Thu, 6 Feb 2020 16:51:24 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EB=AF=B8=20=EC=97=B4=EB=A6=B0=20?= =?UTF-8?q?=EB=B0=A9=EC=97=90=20=EB=8C=80=ED=95=B4=EC=84=9C=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EC=97=B4=EA=B3=A0=EC=9E=90=20=ED=95=A0=EB=95=8C=20?= =?UTF-8?q?=EA=B0=B1=EC=8B=A0=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95.=20ChatStore.selectedRoom=20effe?= =?UTF-8?q?ct=20=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/store/messenger/chat/actions.ts | 2 + .../src/app/store/messenger/event/reducers.ts | 2 +- .../src/app/store/messenger/room/effects.ts | 43 +++++++++++++------ 3 files changed, 32 insertions(+), 15 deletions(-) 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(