Skip to content

Commit

Permalink
fix(Assistant): Now exclude realtime message if not relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Nov 5, 2024
1 parent 9327e30 commit dcc1551
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/assistant/AssistantProvider.jsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -19,6 +20,7 @@ export const useAssistant = () => {
}

const AssistantProvider = ({ children }) => {
const { conversationId } = useParams()
const client = useClient()
const [assistantState, setAssistantState] = useState({
message: {},
Expand All @@ -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)
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion src/assistant/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dcc1551

Please sign in to comment.