feat: Enhance topic message clearing functionality

关于“清空话题”的Bug反馈 #2107

close #2107
This commit is contained in:
kangfenmao 2025-02-21 16:48:04 +08:00
parent 83c8f06b81
commit d5b9c35f0a
2 changed files with 15 additions and 6 deletions

View File

@ -162,10 +162,19 @@ const Messages: FC<Props> = ({ assistant, topic, setActiveTopic }) => {
setTimeout(() => EventEmitter.emit(EVENT_NAMES.AI_AUTO_RENAME), 100)
}),
EventEmitter.on(EVENT_NAMES.AI_AUTO_RENAME, autoRenameTopic),
EventEmitter.on(EVENT_NAMES.CLEAR_MESSAGES, () => {
EventEmitter.on(EVENT_NAMES.CLEAR_MESSAGES, (data: Topic) => {
const defaultTopic = getDefaultTopic(assistant.id)
// Clear messages of other topics
if (data && data.id !== topic.id) {
TopicManager.clearTopicMessages(data.id)
updateTopic({ ...data, name: defaultTopic.name, messages: [] })
return
}
// Clear messages of current topic
setMessages([])
setDisplayMessages([])
const defaultTopic = getDefaultTopic(assistant.id)
const _topic = getTopic(assistant, topic.id)
_topic && updateTopic({ ..._topic, name: defaultTopic.name, messages: [] })
TopicManager.clearTopicMessages(topic.id)

View File

@ -60,17 +60,17 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
deleteTimerRef.current = setTimeout(() => setDeletingTopicId(null), 2000)
}, [])
const onClearMessages = useCallback(() => {
const onClearMessages = useCallback((topic: Topic) => {
window.keyv.set(EVENT_NAMES.CHAT_COMPLETION_PAUSED, true)
store.dispatch(setGenerating(false))
EventEmitter.emit(EVENT_NAMES.CLEAR_MESSAGES)
EventEmitter.emit(EVENT_NAMES.CLEAR_MESSAGES, topic)
}, [])
const handleConfirmDelete = useCallback(
async (topic: Topic, e: React.MouseEvent) => {
e.stopPropagation()
if (assistant.topics.length === 1) {
return onClearMessages()
return onClearMessages(topic)
}
await modelGenerating()
const index = findIndex(assistant.topics, (t) => t.id === topic.id)
@ -187,7 +187,7 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
window.modal.confirm({
title: t('chat.input.clear.content'),
centered: true,
onOk: onClearMessages
onOk: () => onClearMessages(topic)
})
}
},