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