diff --git a/src/assistant/AssistantProvider.jsx b/src/assistant/AssistantProvider.jsx index b2cc4c255..0ab25871b 100644 --- a/src/assistant/AssistantProvider.jsx +++ b/src/assistant/AssistantProvider.jsx @@ -1,4 +1,5 @@ import React, { useMemo, useContext, useState, useCallback } from 'react' +import { useParams } from 'react-router-dom' import set from 'lodash/set' import { useClient } from 'cozy-client' @@ -19,6 +20,7 @@ export const useAssistant = () => { } const AssistantProvider = ({ children }) => { + const { conversationId } = useParams() const client = useClient() const [assistantState, setAssistantState] = useState({ message: {}, @@ -31,10 +33,10 @@ const AssistantProvider = ({ children }) => { { [CHAT_CONVERSATIONS_DOCTYPE]: { created: res => { - pushMessagesIdInState(res, setAssistantState) + pushMessagesIdInState(conversationId, res, setAssistantState) }, updated: res => { - pushMessagesIdInState(res, setAssistantState) + pushMessagesIdInState(conversationId, res, setAssistantState) } } }, diff --git a/src/assistant/helpers.js b/src/assistant/helpers.js index 4fa0e8b10..6d53d5458 100644 --- a/src/assistant/helpers.js +++ b/src/assistant/helpers.js @@ -7,7 +7,9 @@ export const getInstantMessage = assistantState => export const makeConversationId = () => `${Date.now()}-${Math.floor(Math.random() * 90000) + 10000}` -export const pushMessagesIdInState = (res, setState) => { +export const pushMessagesIdInState = (id, res, setState) => { + if (id !== res._id) return + const messagesId = res.messages.map(message => message.id) setState(v => ({ ...v,