Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

fix: remove related messages when deleting conversations.

Wentao Lyue796a19136b6
diff --git a/api/models/Conversation.js b/api/models/Conversation.js
index fed22793d2..c7ff0f18f8 100644
--- a/api/models/Conversation.js
+++ b/api/models/Conversation.js
@@ -149,9 +149,10 @@ module.exports = {
}
},
deleteConvos: async (user, filter) => {
- let deleteCount = await Conversation.deleteMany({ ...filter, user }).exec();
- console.log('deleteCount', deleteCount);
- deleteCount.messages = await deleteMessages({ ...filter, user });
+ let toRemove = await Conversation.find({...filter, user}).select('conversationId')
+ const ids = toRemove.map(instance => instance.conversationId);
+ let deleteCount = await Conversation.deleteMany({...filter, user}).exec();
+ deleteCount.messages = await deleteMessages({conversationId: {$in: ids}});
return deleteCount;
}
};