实现IM系统与PC端一致的WebSocket连接,优化聊天功能,支持多端消息同步,更新联系人和会话列表接口,增强用户体验。
This commit is contained in:
@@ -1277,7 +1277,11 @@
|
||||
content: imagePath,
|
||||
msgType: IM_MSG_TYPE_IMAGE,
|
||||
});
|
||||
messageList.value.push(msg);
|
||||
//update-begin---author:xsl ---date:20260720 for:【IM多端同步】发送成功与 WS 回推竞态去重-----------
|
||||
if (!messageList.value.some((item) => item.id === msg.id)) {
|
||||
messageList.value.push(msg);
|
||||
}
|
||||
//update-end---author:xsl ---date:20260720 for:【IM多端同步】发送成功与 WS 回推竞态去重-----------
|
||||
appendCachedMessage(activeConversationId.value, msg);
|
||||
await nextTick();
|
||||
scrollToBottom();
|
||||
@@ -1339,7 +1343,11 @@
|
||||
content,
|
||||
msgType: IM_MSG_TYPE_BIZ_RECORD,
|
||||
});
|
||||
messageList.value.push(msg);
|
||||
//update-begin---author:xsl ---date:20260720 for:【IM多端同步】发送成功与 WS 回推竞态去重-----------
|
||||
if (!messageList.value.some((item) => item.id === msg.id)) {
|
||||
messageList.value.push(msg);
|
||||
}
|
||||
//update-end---author:xsl ---date:20260720 for:【IM多端同步】发送成功与 WS 回推竞态去重-----------
|
||||
appendCachedMessage(activeConversationId.value, msg);
|
||||
await nextTick();
|
||||
scrollToBottom();
|
||||
@@ -1356,7 +1364,11 @@
|
||||
sending.value = true;
|
||||
try {
|
||||
const msg = await sendMessage({ conversationId: activeConversationId.value, content, msgType: IM_MSG_TYPE_TEXT });
|
||||
messageList.value.push(msg);
|
||||
//update-begin---author:xsl ---date:20260720 for:【IM多端同步】发送成功与 WS 回推竞态去重-----------
|
||||
if (!messageList.value.some((item) => item.id === msg.id)) {
|
||||
messageList.value.push(msg);
|
||||
}
|
||||
//update-end---author:xsl ---date:20260720 for:【IM多端同步】发送成功与 WS 回推竞态去重-----------
|
||||
appendCachedMessage(activeConversationId.value, msg);
|
||||
await nextTick();
|
||||
scrollToBottom();
|
||||
@@ -1425,16 +1437,46 @@
|
||||
const isGroupMessage = data.convType === 'group';
|
||||
const matchedGroup = groupList.value.find((item) => item.conversationId === conversationId);
|
||||
const isCurrentConversation = resolveIsCurrentConversation(conversationId, senderId, isGroupMessage || !!matchedGroup);
|
||||
//update-begin---author:xsl ---date:20260720 for:【IM多端同步】本人其他端消息不累加未读-----------
|
||||
const isSelfMessage = !!senderId && senderId === currentUserId.value;
|
||||
//update-end---author:xsl ---date:20260720 for:【IM多端同步】本人其他端消息不累加未读-----------
|
||||
|
||||
//update-begin---author:xsl ---date:20260528 for:【IM聊天-OA】当前会话 WS 消息即时渲染,避免只更新侧栏摘要-----------
|
||||
if (isCurrentConversation) {
|
||||
alignActiveConversationId(conversationId);
|
||||
appendIncomingMessage(data);
|
||||
markRead(conversationId);
|
||||
//update-begin---author:xsl ---date:20260720 for:【IM多端同步】本人消息无需 markRead-----------
|
||||
if (!isSelfMessage) {
|
||||
markRead(conversationId);
|
||||
}
|
||||
//update-end---author:xsl ---date:20260720 for:【IM多端同步】本人消息无需 markRead-----------
|
||||
return;
|
||||
}
|
||||
//update-end---author:xsl ---date:20260528 for:【IM聊天-OA】当前会话 WS 消息即时渲染,避免只更新侧栏摘要-----------
|
||||
|
||||
//update-begin---author:xsl ---date:20260720 for:【IM多端同步】非当前会话的本人消息只更新摘要-----------
|
||||
if (isSelfMessage) {
|
||||
if (isGroupMessage || matchedGroup) {
|
||||
if (matchedGroup) {
|
||||
patchGroup(conversationId, {
|
||||
lastContent: preview,
|
||||
lastTime: data.createTime,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
const peer = deptMembers.value.find((item) => item.conversationId === conversationId);
|
||||
if (peer?.id) {
|
||||
patchDeptMember(peer.id, {
|
||||
conversationId,
|
||||
lastContent: preview,
|
||||
lastTime: data.createTime,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
//update-end---author:xsl ---date:20260720 for:【IM多端同步】非当前会话的本人消息只更新摘要-----------
|
||||
|
||||
if (isGroupMessage || matchedGroup) {
|
||||
if (!matchedGroup) {
|
||||
//update-begin---author:xsl ---date:20260528 for:【IM聊天】群聊不在列表时,loadGroups 后不再手动 +1(API 已含正确未读数,再 +1 会导致角标翻倍)-----------
|
||||
|
||||
@@ -479,9 +479,13 @@ export function handleImChatSocket(data: Record<string, any>) {
|
||||
activeConversationId = conversationId;
|
||||
}
|
||||
|
||||
const userStore = useUserStoreWithOut();
|
||||
const currentUserId = userStore.getUserInfo?.id || '';
|
||||
//update-begin---author:xsl ---date:20260720 for:【IM多端同步】本人其他端发送的消息只同步摘要不增加未读-----------
|
||||
const isSelfMessage = !!currentUserId && senderId === currentUserId;
|
||||
//update-end---author:xsl ---date:20260720 for:【IM多端同步】本人其他端发送的消息只同步摘要不增加未读-----------
|
||||
|
||||
if (isActiveConversation) {
|
||||
const userStore = useUserStoreWithOut();
|
||||
const currentUserId = userStore.getUserInfo?.id || '';
|
||||
appendCachedMessage(conversationId, {
|
||||
id: data.messageId,
|
||||
conversationId,
|
||||
@@ -514,6 +518,34 @@ export function handleImChatSocket(data: Record<string, any>) {
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (isSelfMessage) {
|
||||
//update-begin---author:xsl ---date:20260720 for:【IM多端同步】非当前会话收到本人消息:更新摘要、不累加未读-----------
|
||||
const preview = formatImMessagePreview(data.content, data.msgType);
|
||||
if (isGroupMessage) {
|
||||
const current = groupUnreadCache.get(conversationId) || { unreadCount: 0 };
|
||||
groupUnreadCache.set(conversationId, {
|
||||
unreadCount: current.unreadCount || 0,
|
||||
lastContent: preview,
|
||||
lastTime: data.createTime as string,
|
||||
});
|
||||
syncImUnreadFromMembers([...(getCachedMembers() || []), ...getCachedGroupUnreadItems()]);
|
||||
} else {
|
||||
const members = getCachedMembers() || [];
|
||||
const peerMember = members.find((item) => item.conversationId === conversationId);
|
||||
if (peerMember?.id) {
|
||||
patchCachedMember(
|
||||
peerMember.id,
|
||||
{
|
||||
conversationId,
|
||||
lastContent: preview,
|
||||
lastTime: data.createTime,
|
||||
},
|
||||
{ moveToTop: true },
|
||||
);
|
||||
}
|
||||
syncImUnreadFromMembers([...(getCachedMembers() || []), ...getCachedGroupUnreadItems()]);
|
||||
}
|
||||
//update-end---author:xsl ---date:20260720 for:【IM多端同步】非当前会话收到本人消息:更新摘要、不累加未读-----------
|
||||
} else if (isGroupMessage) {
|
||||
//update-begin---author:xsl ---date:20260528 for:【IM聊天】非活跃群聊收到 WS 消息:累加群聊未读并更新顶部角标-----------
|
||||
incrementGroupUnread(conversationId, formatImMessagePreview(data.content, data.msgType), data.createTime as string);
|
||||
|
||||
Reference in New Issue
Block a user