From aa9d15e2e4af96c0adebf9255c7e6c0196f13d8a Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 4 Aug 2021 19:25:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=9B=91=E5=90=AC=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=BE=A4=E7=BB=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/api/socket.ts | 2 +- shared/redux/setup.ts | 4 ++++ shared/redux/slices/group.ts | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/shared/api/socket.ts b/shared/api/socket.ts index a1fd8f4e..42871d7a 100644 --- a/shared/api/socket.ts +++ b/shared/api/socket.ts @@ -30,7 +30,7 @@ export class AppSocket { const matched = this.listener.filter(([ev]) => ev === eventName); // 匹配到的监听器列表 if (matched.length === 0) { // 没有匹配到任何处理函数 - console.warn(`[Socket IO] Unhandler event: ${eventName}`); + console.warn(`[Socket IO] Unhandler event: ${eventName}`, data); return; } diff --git a/shared/redux/setup.ts b/shared/redux/setup.ts index 2434e1ab..c46c895d 100644 --- a/shared/redux/setup.ts +++ b/shared/redux/setup.ts @@ -69,4 +69,8 @@ function listenNotify(socket: AppSocket, store: AppStore) { store.dispatch(userActions.removeFriendRequest(requestId)); } ); + + socket.listen('group.updateInfo', (groupInfo) => { + store.dispatch(groupActions.updateGroup(groupInfo)); + }); } diff --git a/shared/redux/slices/group.ts b/shared/redux/slices/group.ts index ecd12680..889f5abf 100644 --- a/shared/redux/slices/group.ts +++ b/shared/redux/slices/group.ts @@ -23,6 +23,14 @@ const groupSlice = createSlice({ }; } }, + updateGroup(state, action: PayloadAction) { + const group = action.payload; + const groupId = group._id; + state.groups[groupId] = { + ...state.groups[groupId], + ...group, + }; + }, }, });