Skip to content

Commit dcc1551

Browse files
committed
fix(Assistant): Now exclude realtime message if not relevant
1 parent 9327e30 commit dcc1551

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/assistant/AssistantProvider.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useMemo, useContext, useState, useCallback } from 'react'
2+
import { useParams } from 'react-router-dom'
23
import set from 'lodash/set'
34

45
import { useClient } from 'cozy-client'
@@ -19,6 +20,7 @@ export const useAssistant = () => {
1920
}
2021

2122
const AssistantProvider = ({ children }) => {
23+
const { conversationId } = useParams()
2224
const client = useClient()
2325
const [assistantState, setAssistantState] = useState({
2426
message: {},
@@ -31,10 +33,10 @@ const AssistantProvider = ({ children }) => {
3133
{
3234
[CHAT_CONVERSATIONS_DOCTYPE]: {
3335
created: res => {
34-
pushMessagesIdInState(res, setAssistantState)
36+
pushMessagesIdInState(conversationId, res, setAssistantState)
3537
},
3638
updated: res => {
37-
pushMessagesIdInState(res, setAssistantState)
39+
pushMessagesIdInState(conversationId, res, setAssistantState)
3840
}
3941
}
4042
},

src/assistant/helpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ export const getInstantMessage = assistantState =>
77
export const makeConversationId = () =>
88
`${Date.now()}-${Math.floor(Math.random() * 90000) + 10000}`
99

10-
export const pushMessagesIdInState = (res, setState) => {
10+
export const pushMessagesIdInState = (id, res, setState) => {
11+
if (id !== res._id) return
12+
1113
const messagesId = res.messages.map(message => message.id)
1214
setState(v => ({
1315
...v,

0 commit comments

Comments
 (0)