fix: Cleared thread last message is not updated (#1225)
When a user clears the conversation in a thread, the last message displayed was still the old one. This led to confusion about whether or not the user had successfully cleared the conversation.
This commit is contained in:
parent
a7f186cc5e
commit
85641741cf
@ -22,6 +22,7 @@ import {
|
|||||||
setActiveThreadIdAtom,
|
setActiveThreadIdAtom,
|
||||||
deleteThreadStateAtom,
|
deleteThreadStateAtom,
|
||||||
threadStatesAtom,
|
threadStatesAtom,
|
||||||
|
updateThreadStateLastMessageAtom,
|
||||||
} from '@/helpers/atoms/Thread.atom'
|
} from '@/helpers/atoms/Thread.atom'
|
||||||
|
|
||||||
export default function useDeleteThread() {
|
export default function useDeleteThread() {
|
||||||
@ -33,21 +34,23 @@ export default function useDeleteThread() {
|
|||||||
const deleteMessages = useSetAtom(deleteChatMessagesAtom)
|
const deleteMessages = useSetAtom(deleteChatMessagesAtom)
|
||||||
const cleanMessages = useSetAtom(cleanChatMessagesAtom)
|
const cleanMessages = useSetAtom(cleanChatMessagesAtom)
|
||||||
const deleteThreadState = useSetAtom(deleteThreadStateAtom)
|
const deleteThreadState = useSetAtom(deleteThreadStateAtom)
|
||||||
|
|
||||||
const threadStates = useAtomValue(threadStatesAtom)
|
const threadStates = useAtomValue(threadStatesAtom)
|
||||||
|
const updateThreadLastMessage = useSetAtom(updateThreadStateLastMessageAtom)
|
||||||
|
|
||||||
const cleanThread = async (threadId: string) => {
|
const cleanThread = async (threadId: string) => {
|
||||||
if (threadId) {
|
if (threadId) {
|
||||||
const thread = threads.filter((c) => c.id === threadId)[0]
|
const thread = threads.filter((c) => c.id === threadId)[0]
|
||||||
cleanMessages(threadId)
|
cleanMessages(threadId)
|
||||||
|
|
||||||
if (thread)
|
if (thread) {
|
||||||
await extensionManager
|
await extensionManager
|
||||||
.get<ConversationalExtension>(ExtensionType.Conversational)
|
.get<ConversationalExtension>(ExtensionType.Conversational)
|
||||||
?.writeMessages(
|
?.writeMessages(
|
||||||
threadId,
|
threadId,
|
||||||
messages.filter((msg) => msg.role === ChatCompletionRole.System)
|
messages.filter((msg) => msg.role === ChatCompletionRole.System)
|
||||||
)
|
)
|
||||||
|
updateThreadLastMessage(threadId, undefined)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user