🐛 fix(im): 修复切会话 watch 仅监听 targetId 导致私聊与群聊 id 同号时不触发
home/index.vue 已读 watch、MessagePanel 滚动 / 侧栏 / 群资料预拉 watch 都只看 targetId, 私聊 1 切群 1 时不会触发,会把侧栏 / 新消息浮窗 / 滚动状态 / 已读上报漏掉,且不跑 ensureGroupData。 对齐多选 + 语音那两条 watch,统一改成监听 [type, targetId]。im
parent
0323566878
commit
0b07091e79
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue