refactor(weChat): 重构消息处理逻辑并优化组件结构

将消息滚动逻辑移至MessageRecord组件
统一处理群组和好友消息的ID判断
移除ChatWindow中不必要的props传递
This commit is contained in:
超级老白兔
2025-09-05 11:05:49 +08:00
parent 7c9ae9e339
commit d31edeef65
3 changed files with 36 additions and 44 deletions

View File

@@ -89,20 +89,27 @@ export const useWeChatStore = create<WeChatState>()(
receivedMsg: message => {
const currentContract = useWeChatStore.getState().currentContract;
//判断群还是好友
const getMessageId =
currentContract?.chatroomId || message.wechatFriendId;
const isGroup = currentContract?.chatroomId;
if (
currentContract &&
currentContract.wechatAccountId == message.wechatAccountId &&
currentContract.id == message.wechatFriendId
currentContract.id == getMessageId
) {
console.log("进入");
if (isGroup) {
message.unreadCount = 1;
}
set(state => ({
currentMessages: [...state.currentMessages, message],
}));
} else {
//更新消息列表unread数值根据接收的++1 这样
const chatSessions = useCkChatStore.getState().chatSessions;
const session = chatSessions.find(
item => item.id == message.wechatFriendId,
);
const session = chatSessions.find(item => item.id == getMessageId);
if (session) {
session.unreadCount = Number(session.unreadCount) + 1;
updateChatSession(session);