diff --git a/src/views/im/home/index.vue b/src/views/im/home/index.vue index bcfb88e21..fa04284ff 100644 --- a/src/views/im/home/index.vue +++ b/src/views/im/home/index.vue @@ -146,19 +146,22 @@ onUnmounted(() => { /** * 当前会话切换:本地清零未读 + 上报后端已读 + 私聊补"对方已读到哪条" * - * 只针对当前 active 会话做处理,其它会话已读状态由 WebSocket READ/RECEIPT 事件被动同步。 - * 私聊补一次拉对方已读位置,弥补离线 / 多端漏掉的 RECEIPT 推送 + * type+targetId 一起监听:私聊与群聊 id 同号时切换也能触发;其它会话已读状态由 WebSocket + * READ / RECEIPT 事件被动同步。私聊补一次拉对方已读位置,弥补离线 / 多端漏掉的 RECEIPT 推送 */ watch( - () => conversationStore.activeConversation?.targetId, - async (targetId) => { + () => [ + conversationStore.activeConversation?.type, + conversationStore.activeConversation?.targetId + ], + async ([type, targetId]) => { if (!targetId) { return } // 本地清零未读 + 上报后端已读,让其它端 / 对方 UI 同步 await readActive() // 私聊补一次"对方已读到哪条",弥补离线 / 多端漏掉的 RECEIPT 推送 - if (conversationStore.activeConversation?.type === ImConversationType.PRIVATE) { + if (type === ImConversationType.PRIVATE) { void syncPrivateReadStatus(targetId) } } diff --git a/src/views/im/home/pages/conversation/components/message/MessagePanel.vue b/src/views/im/home/pages/conversation/components/message/MessagePanel.vue index 3077025c5..2962ad580 100644 --- a/src/views/im/home/pages/conversation/components/message/MessagePanel.vue +++ b/src/views/im/home/pages/conversation/components/message/MessagePanel.vue @@ -573,19 +573,22 @@ watch( /** * 切换会话:清空"在不在底部"相关状态、强制滚到底部、群会话预拉资料 * - * immediate:true 让首次进入页面就能正确初始化(无需等到第一次切换) + * type+targetId 一起监听:私聊与群聊 id 同号时切换也能触发;immediate:true 让首次进入页面就能初始化 */ watch( - () => conversationStore.activeConversation?.targetId, - (targetId) => { - // 切群时上一会话的"未读累计 + 浮窗显示"必须清掉,否则会带到新会话里看起来很突兀 + () => [ + conversationStore.activeConversation?.type, + conversationStore.activeConversation?.targetId + ], + ([type, targetId]) => { + // 切会话时上一会话的「未读累计 + 浮窗显示」必须清掉,否则会带到新会话里看起来很突兀 newMessageCount.value = 0 showJumpToBottom.value = false // 抽屉里展示的群信息 / 好友信息属于上一会话,切会话时统一关掉 sideVisible.value = false scrollToBottom() // 仅群聊预拉详情 / 成员(私聊对端在首屏 fetchFriends 时就拉了) - if (targetId && conversationStore.activeConversation?.type === ImConversationType.GROUP) { + if (targetId && type === ImConversationType.GROUP) { ensureGroupData(targetId) } },