From a9c34162369f72da506930f8a93225609aa03bdd Mon Sep 17 00:00:00 2001 From: NamH Date: Wed, 20 Dec 2023 12:36:31 +0700 Subject: [PATCH] fix(Thread): #1064 message being added to wrong thread if switching thread (#1108) when waiting for LLM to response Signed-off-by: James Co-authored-by: James --- web/helpers/atoms/ChatMessage.atom.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/web/helpers/atoms/ChatMessage.atom.ts b/web/helpers/atoms/ChatMessage.atom.ts index 33309e6fc..b11e8f3be 100644 --- a/web/helpers/atoms/ChatMessage.atom.ts +++ b/web/helpers/atoms/ChatMessage.atom.ts @@ -60,19 +60,21 @@ export const addOldMessagesAtom = atom( export const addNewMessageAtom = atom( null, (get, set, newMessage: ThreadMessage) => { - const threadId = get(getActiveThreadIdAtom) - if (!threadId) return - - const currentMessages = get(chatMessages)[threadId] ?? [] + const currentMessages = get(chatMessages)[newMessage.thread_id] ?? [] const updatedMessages = [...currentMessages, newMessage] const newData: Record = { ...get(chatMessages), } - newData[threadId] = updatedMessages + newData[newMessage.thread_id] = updatedMessages set(chatMessages, newData) + // Update thread last message - set(updateThreadStateLastMessageAtom, threadId, newMessage.content) + set( + updateThreadStateLastMessageAtom, + newMessage.thread_id, + newMessage.content + ) } )