fix(im):修复对话置顶被关闭时,默认还选择了第一个置顶对话,导致又被打开。

im
YunaiV 2026-05-04 12:00:03 +08:00
parent b6ca1187b1
commit 63c4dd1096
1 changed files with 22 additions and 3 deletions

View File

@ -35,6 +35,8 @@ import { useDraftStore } from './store/draftStore'
import { useMessagePuller } from './composables/useMessagePuller'
import { useMessageSender } from './composables/useMessageSender'
import { ImConversationType } from '../utils/constants'
import { StorageKeys } from '../utils/storage'
import type { Conversation } from './types'
import ToolBar from './components/ToolBar.vue'
import UserInfoCard from './components/user/UserInfoCard.vue'
import ContextMenu from './components/ContextMenu.vue'
@ -84,10 +86,11 @@ onMounted(async () => {
webSocketStore.connect()
await pullOnce()
// 4.
// 4.
const sorted = conversationStore.getSortedConversations
if (sorted.length > 0 && !conversationStore.activeConversation) {
conversationStore.setActiveConversation(sorted[0])
const firstVisible = pickFirstVisibleConversation(sorted)
if (firstVisible && !conversationStore.activeConversation) {
conversationStore.setActiveConversation(firstVisible)
}
} catch (e) {
// 1. loadingpullOnce finally saveConversations return
@ -97,6 +100,22 @@ onMounted(async () => {
}
})
/**
* 选首屏自动激活的会话置顶分组折叠时跳过被折叠隐藏的置顶项避免激活后被自动顶上来
*
* 折叠态判定只看用户开关非置顶 / 有未读的置顶项始终可见全是可折叠置顶时回退到 sorted[0] 兜底
*/
function pickFirstVisibleConversation(sorted: Conversation[]): Conversation | undefined {
if (sorted.length === 0) {
return undefined
}
const pinnedExpanded = localStorage.getItem(StorageKeys.conversationPinnedExpanded) === 'true'
if (pinnedExpanded) {
return sorted[0]
}
return sorted.find((c) => !c.top || (!c.muted && (c.unreadCount || 0) > 0)) ?? sorted[0]
}
/** 标签关闭前 flush 草稿队列debounce 默认 trail-edge 触发,最后一次输入可能还压在队列里 */
function onBeforeUnload() {
draftStore.flushPersist()