🐛 fix(im): 修复切会话 watch 仅监听 targetId 导致私聊与群聊 id 同号时不触发

home/index.vue 已读 watch、MessagePanel 滚动 / 侧栏 / 群资料预拉 watch 都只看 targetId,
私聊 1 切群 1 时不会触发,会把侧栏 / 新消息浮窗 / 滚动状态 / 已读上报漏掉,且不跑 ensureGroupData。
对齐多选 + 语音那两条 watch,统一改成监听 [type, targetId]。
im
YunaiV 2026-05-07 21:26:40 +08:00
parent 0323566878
commit 0b07091e79
2 changed files with 16 additions and 10 deletions

View File

@ -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)
}
}

View File

@ -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)
}
},