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.unreadCount !== conversationData.unreadCount
) {
//
//
conversationList.value[existingIndex] = {
...conversationData,
//
avatar: existing.avatar || conversationData.avatar,
//
unreadCount: Math.max(
existing.unreadCount || 0,
conversationData.unreadCount || 0
),
// 使 TIM SDK 使 Math.max
// unreadCount N 0
unreadCount: conversationData.unreadCount || 0
};
needSort = true;
console.log(
@ -367,40 +365,12 @@ const setupConversationListener = () => {
globalTimChatManager.setCallback("onMessageReceived", (message) => {
console.log("消息列表页面收到新消息:", message);
//
const conversationID = message.conversationID;
const conversationIndex = conversationList.value.findIndex(
(conv) => conv.conversationID === conversationID
);
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
);
}
//
// TIM SDK onConversationListUpdated
// +1
//
// onConversationListUpdated
//
});
};

View File

@ -144,7 +144,10 @@ function mergeConversationData(conversation, groupDetailsMap) {
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
}
}