no message

This commit is contained in:
wangdongbo 2026-02-10 16:47:19 +08:00
parent 4e6cdf4bdd
commit 17aefb966e
2 changed files with 14 additions and 41 deletions

View File

@ -330,16 +330,14 @@ const setupConversationListener = () => {
existing.lastMessageTime !== conversationData.lastMessageTime || existing.lastMessageTime !== conversationData.lastMessageTime ||
existing.unreadCount !== conversationData.unreadCount existing.unreadCount !== conversationData.unreadCount
) { ) {
// //
conversationList.value[existingIndex] = { conversationList.value[existingIndex] = {
...conversationData, ...conversationData,
// //
avatar: existing.avatar || conversationData.avatar, avatar: existing.avatar || conversationData.avatar,
// // 使 TIM SDK 使 Math.max
unreadCount: Math.max( // unreadCount N 0
existing.unreadCount || 0, unreadCount: conversationData.unreadCount || 0
conversationData.unreadCount || 0
),
}; };
needSort = true; needSort = true;
console.log( console.log(
@ -367,40 +365,12 @@ const setupConversationListener = () => {
globalTimChatManager.setCallback("onMessageReceived", (message) => { globalTimChatManager.setCallback("onMessageReceived", (message) => {
console.log("消息列表页面收到新消息:", message); console.log("消息列表页面收到新消息:", message);
// //
const conversationID = message.conversationID; // TIM SDK onConversationListUpdated
const conversationIndex = conversationList.value.findIndex( // +1
(conv) => conv.conversationID === conversationID //
); // onConversationListUpdated
//
if (conversationIndex !== -1) {
const conversation = conversationList.value[conversationIndex];
//
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
// groupID
const currentGroupID = currentPage?.options?.groupID;
const isViewingThisConversation =
currentPage?.route === "pages/message/index" &&
currentGroupID === conversation.groupID;
//
if (isViewingThisConversation) {
console.log("用户正在查看该会话,不增加未读数");
return;
}
//
conversation.unreadCount = (conversation.unreadCount || 0) + 1;
console.log(
"已更新会话未读数:",
conversation.name,
"unreadCount:",
conversation.unreadCount
);
}
}); });
}; };

View File

@ -144,7 +144,10 @@ function mergeConversationData(conversation, groupDetailsMap) {
name: formatConversationName(groupDetail), name: formatConversationName(groupDetail),
// 更新头像(优先使用已有头像,避免闪动) // 更新头像(优先使用已有头像,避免闪动)
avatar: conversation.avatar || groupDetail.patient?.avatar || '/static/default-avatar.png' avatar: conversation.avatar || groupDetail.patient?.avatar || '/static/default-avatar.png',
// 【修复】保留未读消息数(确保不被覆盖)
unreadCount: conversation.unreadCount || 0
} }
} }