mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-05-13 15:10:05 +00:00
支持一键已读
This commit is contained in:
@@ -1453,6 +1453,7 @@ function ChatPage(props: ChatPageProps) {
|
||||
const [showScrollToBottom, setShowScrollToBottom] = useState(false)
|
||||
const [sidebarWidth, setSidebarWidth] = useState(260)
|
||||
const [isResizing, setIsResizing] = useState(false)
|
||||
const [isMarkingAllSessionsRead, setIsMarkingAllSessionsRead] = useState(false)
|
||||
const [showDetailPanel, setShowDetailPanel] = useState(false)
|
||||
const [showGroupMembersPanel, setShowGroupMembersPanel] = useState(false)
|
||||
const [sessionDetail, setSessionDetail] = useState<SessionDetail | null>(null)
|
||||
@@ -3130,6 +3131,35 @@ function ChatPage(props: ChatPageProps) {
|
||||
}
|
||||
}
|
||||
|
||||
const handleMarkAllSessionsRead = async () => {
|
||||
if (isMarkingAllSessionsRead || isLoadingSessions || isRefreshingSessions) return
|
||||
setIsMarkingAllSessionsRead(true)
|
||||
setConnectionError(null)
|
||||
try {
|
||||
const result = await window.electronAPI.chat.markAllSessionsRead()
|
||||
if (!result.success) {
|
||||
setConnectionError(result.error || '一键已读失败')
|
||||
return
|
||||
}
|
||||
|
||||
const latestSessions = useChatStore.getState().sessions || []
|
||||
const nextSessions = latestSessions.map((session) => (
|
||||
session.unreadCount > 0 ? { ...session, unreadCount: 0 } : session
|
||||
))
|
||||
setSessions(nextSessions)
|
||||
sessionsRef.current = nextSessions
|
||||
|
||||
const scope = await resolveChatCacheScope()
|
||||
persistSessionListCache(scope, nextSessions)
|
||||
await loadSessions({ silent: true })
|
||||
} catch (e) {
|
||||
console.error('一键已读失败:', e)
|
||||
setConnectionError(`一键已读失败: ${String(e)}`)
|
||||
} finally {
|
||||
setIsMarkingAllSessionsRead(false)
|
||||
}
|
||||
}
|
||||
|
||||
// 分批异步加载联系人信息(优化:缓存优先 + 可持续队列 + 首屏优先批次)
|
||||
const enrichSessionsContactInfo = async (sessions: ChatSession[]) => {
|
||||
if (Array.isArray(sessions) && sessions.length > 0) {
|
||||
@@ -6775,6 +6805,15 @@ function ChatPage(props: ChatPageProps) {
|
||||
<button className="icon-btn refresh-btn" onClick={handleRefresh} disabled={isLoadingSessions || isRefreshingSessions}>
|
||||
<RefreshCw size={16} className={(isLoadingSessions || isRefreshingSessions) ? 'spin' : ''} />
|
||||
</button>
|
||||
<button
|
||||
className="icon-btn refresh-btn mark-read-btn"
|
||||
onClick={handleMarkAllSessionsRead}
|
||||
disabled={isMarkingAllSessionsRead || isLoadingSessions || isRefreshingSessions}
|
||||
title="一键已读"
|
||||
aria-label="一键已读"
|
||||
>
|
||||
{isMarkingAllSessionsRead ? <Loader2 size={16} className="spin" /> : <CheckSquare size={16} />}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/* 折叠群 header */}
|
||||
|
||||
1
src/types/electron.d.ts
vendored
1
src/types/electron.d.ts
vendored
@@ -271,6 +271,7 @@ export interface ElectronAPI {
|
||||
chat: {
|
||||
connect: () => Promise<{ success: boolean; error?: string }>
|
||||
getSessions: () => Promise<{ success: boolean; sessions?: ChatSession[]; error?: string }>
|
||||
markAllSessionsRead: () => Promise<{ success: boolean; error?: string }>
|
||||
getAntiRevokeSessions: () => Promise<{ success: boolean; sessions?: ChatSession[]; error?: string }>
|
||||
getSessionStatuses: (usernames: string[]) => Promise<{
|
||||
success: boolean
|
||||
|
||||
Reference in New Issue
Block a user