feat:新增了切换账号的功能 (#89)

This commit is contained in:
xuncha
2026-01-24 12:43:09 +08:00
committed by GitHub
parent 16cbc6adb1
commit 3a10aeb23e
13 changed files with 300 additions and 86 deletions

View File

@@ -245,6 +245,38 @@ function ChatPage(_props: ChatPageProps) {
}
}, [loadMyAvatar])
const handleAccountChanged = useCallback(async () => {
senderAvatarCache.clear()
senderAvatarLoading.clear()
preloadImageKeysRef.current.clear()
lastPreloadSessionRef.current = null
setSessionDetail(null)
setCurrentSession(null)
setSessions([])
setFilteredSessions([])
setMessages([])
setSearchKeyword('')
setConnectionError(null)
setConnected(false)
setConnecting(false)
setHasMoreMessages(true)
setHasMoreLater(false)
await connect()
}, [
connect,
setConnected,
setConnecting,
setConnectionError,
setCurrentSession,
setFilteredSessions,
setHasMoreLater,
setHasMoreMessages,
setMessages,
setSearchKeyword,
setSessionDetail,
setSessions
])
// 加载会话列表(优化:先返回基础数据,异步加载联系人信息)
const loadSessions = async (options?: { silent?: boolean }) => {
if (options?.silent) {
@@ -842,6 +874,14 @@ function ChatPage(_props: ChatPageProps) {
}
}, [])
useEffect(() => {
const handleChange = () => {
void handleAccountChanged()
}
window.addEventListener('wxid-changed', handleChange as EventListener)
return () => window.removeEventListener('wxid-changed', handleChange as EventListener)
}, [handleAccountChanged])
useEffect(() => {
const nextSet = new Set<string>()
for (const msg of messages) {