mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 11:00:55 +03:00
modify delete chat message method
This commit is contained in:
@@ -409,22 +409,29 @@ export class App {
|
||||
return res.json(results)
|
||||
})
|
||||
|
||||
// Delete all chatmessages from chatflowid
|
||||
// Delete all chatmessages from chatId
|
||||
this.app.delete('/api/v1/chatmessage/:id', async (req: Request, res: Response) => {
|
||||
const chatId = req.params.id
|
||||
const chatMessage = await this.AppDataSource.getRepository(ChatMessage).findOneBy({
|
||||
chatId: chatId
|
||||
})
|
||||
if (!chatMessage) {
|
||||
res.status(404).send(`chatmessage ${chatId} not found`)
|
||||
return
|
||||
}
|
||||
const chatflow = await this.AppDataSource.getRepository(ChatFlow).findOneBy({
|
||||
id: req.params.id
|
||||
id: chatMessage.chatflowid
|
||||
})
|
||||
if (!chatflow) {
|
||||
res.status(404).send(`Chatflow ${req.params.id} not found`)
|
||||
res.status(404).send(`Chatflow ${chatMessage.chatflowid} not found`)
|
||||
return
|
||||
}
|
||||
const flowData = chatflow.flowData
|
||||
const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
|
||||
const nodes = parsedFlowData.nodes
|
||||
let chatId = await getChatId(chatflow.id)
|
||||
if (!chatId) chatId = chatflow.id
|
||||
|
||||
clearSessionMemory(nodes, this.nodesPool.componentNodes, chatId, this.AppDataSource, req.query.sessionId as string)
|
||||
const results = await this.AppDataSource.getRepository(ChatMessage).delete({ chatflowid: req.params.id })
|
||||
const results = await this.AppDataSource.getRepository(ChatMessage).delete({ chatId: chatId })
|
||||
return res.json(results)
|
||||
})
|
||||
|
||||
|
||||
@@ -163,6 +163,7 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
|
||||
|
||||
if (!chatId) {
|
||||
setChatId(data.chatId)
|
||||
localStorage.setItem(`${chatflowid}_INTERNAL`, data.chatId)
|
||||
}
|
||||
if (!isChatFlowAvailableToStream) {
|
||||
setMessages((prevMessages) => [
|
||||
@@ -200,8 +201,10 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
|
||||
|
||||
// Get chatmessages successful
|
||||
useEffect(() => {
|
||||
if (getChatmessageApi.data) {
|
||||
setChatId(getChatmessageApi.data[0]?.chatId)
|
||||
if (getChatmessageApi.data?.length) {
|
||||
const chatId = getChatmessageApi.data[0]?.chatId
|
||||
setChatId(chatId)
|
||||
localStorage.setItem(`${chatflowid}_INTERNAL`, chatId)
|
||||
const loadedMessages = getChatmessageApi.data.map((message) => {
|
||||
const obj = {
|
||||
message: message.content,
|
||||
|
||||
@@ -85,7 +85,9 @@ export const ChatPopUp = ({ chatflowid }) => {
|
||||
|
||||
if (isConfirmed) {
|
||||
try {
|
||||
await chatmessageApi.deleteChatmessage(chatflowid)
|
||||
const chatId = localStorage.getItem(`${chatflowid}_INTERNAL`)
|
||||
await chatmessageApi.deleteChatmessage(chatId)
|
||||
localStorage.removeItem(`${chatflowid}_INTERNAL`)
|
||||
resetChatDialog()
|
||||
enqueueSnackbar({
|
||||
message: 'Succesfully cleared all chat history',
|
||||
|
||||
Reference in New Issue
Block a user