diff --git a/public/script.js b/public/script.js index 21d542518..551d23a7d 100644 --- a/public/script.js +++ b/public/script.js @@ -6319,7 +6319,7 @@ function importCharacter(file) { let currentContext = getContext(); let avatarFileName = `${data.file_name}.png`; let importedCharacter = currentContext.characters.find(character => character.avatar === avatarFileName); - importTags(importedCharacter); + await importTags(importedCharacter); } $("#rm_info_block").transition({ opacity: 1, duration: 1000 }); } diff --git a/public/scripts/tags.js b/public/scripts/tags.js index 69c83a734..6e24bbe78 100644 --- a/public/scripts/tags.js +++ b/public/scripts/tags.js @@ -5,6 +5,7 @@ import { callPopup, menu_type, updateVisibleDivs, + getCharacters, } from "../script.js"; import { selected_group } from "./group-chats.js"; @@ -202,24 +203,42 @@ function selectTag(event, ui, listSelector) { return false; } -function importTags(imported_char) { - //Ignore the tags ROOT and TAVERN +function getExistingTags(new_tags) { + let existing_tags = []; + for (let tag of new_tags) { + if (tags.find(t => t.name === tag)) { + existing_tags.push(tag); + } + } + return existing_tags +} + + +async function importTags(imported_char) { let imported_tags = imported_char.tags.filter(t => t !== "ROOT" && t !== "TAVERN"); - for (let tagName of imported_tags) { + let existingTags = await getExistingTags(imported_tags); + let newTags = imported_tags.filter(t => !existingTags.includes(t)); + let selected_tags = ""; + if(newTags.length === 0) { + await callPopup(`
${existingTags.length} exisiting tags have been found.
`, 'text'); + } else { + selected_tags = await callPopup(`${existingTags.length} exisiting tags have been found.
The following ${newTags.length} new tags will be imported.
`, 'input', newTags.join(', ')); + } + selected_tags = existingTags.concat(selected_tags.split(', ')); + selected_tags = selected_tags.filter(t => t !== ""); + for (let tagName of selected_tags) { let tag = tags.find(t => t.name === tagName); - // create new tag if it doesn't exist if (!tag) { tag = createNewTag(tagName); } - // add tag to the UI and internal map - //appendTagToList(listSelector, tag, { removable: true }); addTagToMap(tag.id); tag_map[imported_char.avatar].push(tag.id); }; saveSettingsDebounced(); printTags(); + getCharacters(); // need to return false to keep the input clear return false;