From 3070cee9ca0b4735ecce2a9b74d5b915bf0a2439 Mon Sep 17 00:00:00 2001 From: Timon Engelke Date: Sat, 13 Nov 2021 00:15:31 +0100 Subject: [PATCH] Delete group after removing it from the group list --- src/node/db/GroupManager.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/node/db/GroupManager.js b/src/node/db/GroupManager.js index 203e21a35..18f91f566 100644 --- a/src/node/db/GroupManager.js +++ b/src/node/db/GroupManager.js @@ -55,9 +55,8 @@ exports.deleteGroup = async (groupID) => { // loop through all sessions and delete them (in parallel) await Promise.all(Object.keys(sessions).map((session) => sessionManager.deleteSession(session))); - // remove group and group2sessions entry + // remove group2sessions entry await db.remove(`group2sessions:${groupID}`); - await db.remove(`group:${groupID}`); // unlist the group let groups = await exports.listAllGroups(); @@ -65,19 +64,18 @@ exports.deleteGroup = async (groupID) => { const index = groups.indexOf(groupID); - if (index === -1) { - // it's not listed + if (index !== -1) { + // remove from the list + groups.splice(index, 1); - return; + // regenerate group list + const newGroups = {}; + groups.forEach((group) => newGroups[group] = 1); + await db.set('groups', newGroups); } - // remove from the list - groups.splice(index, 1); - - // regenerate group list - const newGroups = {}; - groups.forEach((group) => newGroups[group] = 1); - await db.set('groups', newGroups); + // remove group entry + await db.remove(`group:${groupID}`); }; exports.doesGroupExist = async (groupID) => {