diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index cf371fa1b..8a1a6db46 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -1005,7 +1005,7 @@ function select_group_chats(groupId, skipAnimation) { } $("#dialogue_popup").data("group_id", groupId); - callPopup("
This will also delete all your chats with that group. If you want to delete a single conversation, select a "View past chats" option in the lower left menu.
', "del_group"); }); updateFavButtonState(group?.fav ?? false); diff --git a/server.js b/server.js index ce7484a6d..1998123ea 100644 --- a/server.js +++ b/server.js @@ -2181,16 +2181,29 @@ app.post('/deletegroup', jsonParser, async (request, response) => { const id = request.body.id; const pathToGroup = path.join(directories.groups, sanitize(`${id}.json`)); - const pathToChat = path.join(directories.groupChats, sanitize(`${id}.jsonl`)); + + try { + // Delete group chats + const group = json5.parse(fs.readFileSync(pathToGroup)); + + if (group && Array.isArray(group.chats)) { + for (const chat of group.chats) { + console.log('Deleting group chat', chat); + const pathToFile = path.join(directories.groupChats, `${id}.jsonl`); + + if (fs.existsSync(pathToFile)) { + fs.rmSync(pathToFile); + } + } + } + } catch (error) { + console.error('Could not delete group chats. Clean them up manually.', error); + } if (fs.existsSync(pathToGroup)) { fs.rmSync(pathToGroup); } - if (fs.existsSync(pathToChat)) { - fs.rmSync(pathToChat); - } - return response.send({ ok: true }); });