From 85641741cfbb3950da39b161c5001bdbb4ac0e88 Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 27 Dec 2023 15:35:36 +0700 Subject: [PATCH] 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. --- web/hooks/useDeleteThread.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/hooks/useDeleteThread.ts b/web/hooks/useDeleteThread.ts index 168d2dc33..2aac2b207 100644 --- a/web/hooks/useDeleteThread.ts +++ b/web/hooks/useDeleteThread.ts @@ -22,6 +22,7 @@ import { setActiveThreadIdAtom, deleteThreadStateAtom, threadStatesAtom, + updateThreadStateLastMessageAtom, } from '@/helpers/atoms/Thread.atom' export default function useDeleteThread() { @@ -33,21 +34,23 @@ export default function useDeleteThread() { const deleteMessages = useSetAtom(deleteChatMessagesAtom) const cleanMessages = useSetAtom(cleanChatMessagesAtom) const deleteThreadState = useSetAtom(deleteThreadStateAtom) - const threadStates = useAtomValue(threadStatesAtom) + const updateThreadLastMessage = useSetAtom(updateThreadStateLastMessageAtom) const cleanThread = async (threadId: string) => { if (threadId) { const thread = threads.filter((c) => c.id === threadId)[0] cleanMessages(threadId) - if (thread) + if (thread) { await extensionManager .get(ExtensionType.Conversational) ?.writeMessages( threadId, messages.filter((msg) => msg.role === ChatCompletionRole.System) ) + updateThreadLastMessage(threadId, undefined) + } } }