refactor(weChat): 重构消息处理逻辑并优化组件结构
将消息滚动逻辑移至MessageRecord组件 统一处理群组和好友消息的ID判断 移除ChatWindow中不必要的props传递
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user