Skip to content

Commit

Permalink
fix(Thread): janhq#1064 message being added to wrong thread if switch…
Browse files Browse the repository at this point in the history
…ing thread (janhq#1108)

when waiting for LLM to response

Signed-off-by: James <[email protected]>
Co-authored-by: James <[email protected]>
  • Loading branch information
namchuai and James authored Dec 20, 2023
1 parent e21cbc7 commit a9c3416
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions web/helpers/atoms/ChatMessage.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ThreadMessage[]> = {
...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
)
}
)

Expand Down

0 comments on commit a9c3416

Please sign in to comment.