fix: move handling to topics onClearMessages

This commit is contained in:
Tristan Zhang 2025-10-14 21:52:23 +08:00
parent 7c95483137
commit 59a50c346b
2 changed files with 21 additions and 22 deletions

View File

@ -127,11 +127,26 @@ export const Topics: React.FC<Props> = ({ assistant: _assistant, activeTopic, se
deleteTimerRef.current = setTimeout(() => setDeletingTopicId(null), 2000)
}, [])
const onClearMessages = useCallback((topic: Topic) => {
// window.keyv.set(EVENT_NAMES.CHAT_COMPLETION_PAUSED, true)
store.dispatch(setGenerating(false))
EventEmitter.emit(EVENT_NAMES.CLEAR_MESSAGES, topic)
}, [])
const onClearMessages = useCallback(
(topic: Topic) => {
// window.keyv.set(EVENT_NAMES.CHAT_COMPLETION_PAUSED, true)
store.dispatch(setGenerating(false))
EventEmitter.emit(EVENT_NAMES.CLEAR_MESSAGES, topic)
if (assistant.topics.length === 1) {
const updatedTopic = {
...topic,
name: t('chat.default.topic.name'),
isNameManuallyEdited: false
}
updateTopic(updatedTopic)
if (topic.id === activeTopic.id) {
setActiveTopic(updatedTopic)
}
}
},
[assistant.topics.length, t, updateTopic, activeTopic.id, setActiveTopic]
)
const handleConfirmDelete = useCallback(
async (topic: Topic, e: React.MouseEvent) => {

View File

@ -11,7 +11,7 @@ import { transformMessagesAndFetch } from '@renderer/services/OrchestrateService
import { endSpan } from '@renderer/services/SpanManagerService'
import { createStreamProcessor, type StreamProcessorCallbacks } from '@renderer/services/StreamProcessingService'
import store from '@renderer/store'
import { updateTopic, updateTopicUpdatedAt } from '@renderer/store/assistants'
import { updateTopicUpdatedAt } from '@renderer/store/assistants'
import { type ApiServerConfig, type Assistant, type FileMetadata, type Model, type Topic } from '@renderer/types'
import type { AgentSessionEntity, GetAgentSessionResponse } from '@renderer/types/agent'
import { ChunkType } from '@renderer/types/chunk'
@ -1039,22 +1039,6 @@ export const clearTopicMessagesThunk =
dispatch(newMessagesActions.clearTopicMessages(topicId))
cleanupMultipleBlocks(dispatch, blockIdsToDelete)
await clearMessagesFromDBV2(topicId)
const assistants = state.assistants.assistants
for (const assistant of assistants) {
const topic = assistant.topics.find((t) => t.id === topicId)
if (topic) {
if (assistant.topics.length === 1) {
const updatedTopic = {
...topic,
name: t('chat.default.topic.name'),
isNameManuallyEdited: false
}
dispatch(updateTopic({ assistantId: assistant.id, topic: updatedTopic }))
}
break
}
}
} catch (error) {
logger.error(`[clearTopicMessagesThunk] Failed to clear messages for topic ${topicId}:`, error as Error)
}