Delete all group chats with a group.

This commit is contained in:
Cohee
2023-06-04 21:41:22 +03:00
parent d35436921e
commit eb01bcb7c1
2 changed files with 19 additions and 6 deletions

View File

@ -1005,7 +1005,7 @@ function select_group_chats(groupId, skipAnimation) {
}
$("#dialogue_popup").data("group_id", groupId);
callPopup("<h3>Delete the group?</h3>", "del_group");
callPopup('<h3>Delete the group?</h3><p>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.</p>', "del_group");
});
updateFavButtonState(group?.fav ?? false);

View File

@ -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 });
});