refactor: 监听更新群组信息

pull/13/head
moonrailgun 4 years ago
parent 3b2950151e
commit aa9d15e2e4

@ -30,7 +30,7 @@ export class AppSocket {
const matched = this.listener.filter(([ev]) => ev === eventName); // 匹配到的监听器列表 const matched = this.listener.filter(([ev]) => ev === eventName); // 匹配到的监听器列表
if (matched.length === 0) { if (matched.length === 0) {
// 没有匹配到任何处理函数 // 没有匹配到任何处理函数
console.warn(`[Socket IO] Unhandler event: ${eventName}`); console.warn(`[Socket IO] Unhandler event: ${eventName}`, data);
return; return;
} }

@ -69,4 +69,8 @@ function listenNotify(socket: AppSocket, store: AppStore) {
store.dispatch(userActions.removeFriendRequest(requestId)); store.dispatch(userActions.removeFriendRequest(requestId));
} }
); );
socket.listen<GroupInfo>('group.updateInfo', (groupInfo) => {
store.dispatch(groupActions.updateGroup(groupInfo));
});
} }

@ -23,6 +23,14 @@ const groupSlice = createSlice({
}; };
} }
}, },
updateGroup(state, action: PayloadAction<GroupInfo>) {
const group = action.payload;
const groupId = group._id;
state.groups[groupId] = {
...state.groups[groupId],
...group,
};
},
}, },
}); });

Loading…
Cancel
Save