mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-10 15:49:29 +08:00
fix: start animation only if the topic should be renamed (#7125)
This commit is contained in:
parent
1a54447947
commit
198c9e24be
@ -88,20 +88,15 @@ export const finishTopicRenaming = (topicId: string) => {
|
|||||||
}, 700)
|
}, 700)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
const topicRenamingLocks = new Set<string>()
|
||||||
* 判断指定话题是否正在重命名
|
|
||||||
*/
|
|
||||||
export const isTopicRenaming = (topicId: string) => {
|
|
||||||
return store.getState().runtime.chat.renamingTopics.includes(topicId)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const autoRenameTopic = async (assistant: Assistant, topicId: string) => {
|
export const autoRenameTopic = async (assistant: Assistant, topicId: string) => {
|
||||||
if (isTopicRenaming(topicId)) {
|
if (topicRenamingLocks.has(topicId)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
startTopicRenaming(topicId)
|
topicRenamingLocks.add(topicId)
|
||||||
|
|
||||||
const topic = await getTopicById(topicId)
|
const topic = await getTopicById(topicId)
|
||||||
const enableTopicNaming = getStoreSetting('enableTopicNaming')
|
const enableTopicNaming = getStoreSetting('enableTopicNaming')
|
||||||
@ -122,24 +117,36 @@ export const autoRenameTopic = async (assistant: Assistant, topicId: string) =>
|
|||||||
.join('\n\n')
|
.join('\n\n')
|
||||||
.substring(0, 50)
|
.substring(0, 50)
|
||||||
if (topicName) {
|
if (topicName) {
|
||||||
const data = { ...topic, name: topicName } as Topic
|
try {
|
||||||
_setActiveTopic(data)
|
startTopicRenaming(topicId)
|
||||||
store.dispatch(updateTopic({ assistantId: assistant.id, topic: data }))
|
|
||||||
|
const data = { ...topic, name: topicName } as Topic
|
||||||
|
_setActiveTopic(data)
|
||||||
|
store.dispatch(updateTopic({ assistantId: assistant.id, topic: data }))
|
||||||
|
} finally {
|
||||||
|
finishTopicRenaming(topicId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topic && topic.name === i18n.t('chat.default.topic.name') && topic.messages.length >= 2) {
|
if (topic && topic.name === i18n.t('chat.default.topic.name') && topic.messages.length >= 2) {
|
||||||
const { fetchMessagesSummary } = await import('@renderer/services/ApiService')
|
try {
|
||||||
const summaryText = await fetchMessagesSummary({ messages: topic.messages, assistant })
|
startTopicRenaming(topicId)
|
||||||
if (summaryText) {
|
|
||||||
const data = { ...topic, name: summaryText }
|
const { fetchMessagesSummary } = await import('@renderer/services/ApiService')
|
||||||
_setActiveTopic(data)
|
const summaryText = await fetchMessagesSummary({ messages: topic.messages, assistant })
|
||||||
store.dispatch(updateTopic({ assistantId: assistant.id, topic: data }))
|
if (summaryText) {
|
||||||
|
const data = { ...topic, name: summaryText }
|
||||||
|
_setActiveTopic(data)
|
||||||
|
store.dispatch(updateTopic({ assistantId: assistant.id, topic: data }))
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
finishTopicRenaming(topicId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
finishTopicRenaming(topicId)
|
topicRenamingLocks.delete(topicId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user