From f7a82fb4b3c57291acaef2dff1162992780b6602 Mon Sep 17 00:00:00 2001 From: Cohee Date: Sun, 4 Jun 2023 21:23:25 +0300 Subject: [PATCH] Fix duplication of the last character on deletion. Delete tags from tag_map on deletion of character/groups --- public/script.js | 9 ++++++--- public/scripts/group-chats.js | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/public/script.js b/public/script.js index 09ca5ec24..e5ae1ff1a 100644 --- a/public/script.js +++ b/public/script.js @@ -5486,16 +5486,17 @@ $(document).ready(function () { " -- Name: " + characters[this_chid].name ); + const avatar = characters[this_chid].avatar; + const name = characters[this_chid].name; var msg = jQuery("#form_create").serialize(); // ID form jQuery.ajax({ method: "POST", url: "/deletecharacter", beforeSend: function () { - select_rm_info("char_delete", characters[this_chid].name); }, data: msg, cache: false, - success: function (html) { + success: async function (html) { //RossAscends: New handling of character deletion that avoids page refreshes and should have // fixed char corruption due to cache problems. //due to how it is handled with 'popup_type', i couldn't find a way to make my method completely @@ -5516,7 +5517,9 @@ $(document).ready(function () { .text(""); // removes character name from nav tabs clearChat(); // removes deleted char's chat this_chid = undefined; // prevents getCharacters from trying to load an invalid char. - getCharacters(); // gets the new list of characters (that doesn't include the deleted one) + delete tag_map[avatar]; // removes deleted char's avatar from tag_map + await getCharacters(); // gets the new list of characters (that doesn't include the deleted one) + select_rm_info("char_delete", name); // also updates the 'deleted character' message printMessages(); // prints out system user's 'deleted character' message //console.log("#dialogue_popup_ok(del-char) >>>> saving"); saveSettingsDebounced(); // saving settings to keep changes to variables diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 2897803dc..cf371fa1b 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -57,7 +57,7 @@ import { event_types, getCurrentChatId, } from "../script.js"; -import { appendTagToList, createTagMapFromList, getTagsList, applyTagsOnCharacterSelect } from './tags.js'; +import { appendTagToList, createTagMapFromList, getTagsList, applyTagsOnCharacterSelect, tag_map } from './tags.js'; export { selected_group, @@ -786,6 +786,7 @@ async function deleteGroup(id) { if (response.ok) { selected_group = null; + delete tag_map[id]; resetChatState(); clearChat(); printMessages();