From 11b3162aa422b07b4870824699228f6e37888d7a Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Wed, 27 Mar 2024 22:11:19 +0100 Subject: [PATCH 1/7] Include swipeid to all messages in chat --- public/script.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/script.js b/public/script.js index 38ed270cd..77b5728f6 100644 --- a/public/script.js +++ b/public/script.js @@ -1855,6 +1855,7 @@ function insertSVGIcon(mes, extra) { function getMessageFromTemplate({ mesId, + swipeId, characterName, isUser, avatarImg, @@ -1872,6 +1873,7 @@ function getMessageFromTemplate({ const mes = messageTemplate.clone(); mes.attr({ 'mesid': mesId, + 'swipeid': swipeId, 'ch_name': characterName, 'is_user': isUser, 'is_system': !!isSystem, @@ -2018,6 +2020,7 @@ function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll = true let params = { mesId: forceId ?? chat.length - 1, + swipeId: mes.swipes?.indexOf(mes.mes) ?? mes.swipe_id ?? 0, characterName: mes.name, isUser: mes.is_user, avatarImg: avatarImg, From b8c6e6c85c92b6a0487c8b88f7dfe2b180d877a6 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Wed, 27 Mar 2024 23:12:40 +0100 Subject: [PATCH 2/7] Remove unnecessary swipe id check --- public/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index 77b5728f6..c86106b8f 100644 --- a/public/script.js +++ b/public/script.js @@ -2020,7 +2020,7 @@ function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll = true let params = { mesId: forceId ?? chat.length - 1, - swipeId: mes.swipes?.indexOf(mes.mes) ?? mes.swipe_id ?? 0, + swipeId: mes.swipe_id ?? 0, characterName: mes.name, isUser: mes.is_user, avatarImg: avatarImg, From 6ed604593c084a5b4e642cf3a27f9dc2486324a9 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 28 Mar 2024 01:13:54 +0200 Subject: [PATCH 3/7] Copy tags on duplicating --- public/script.js | 5 +++++ public/scripts/BulkEditOverlay.js | 14 +++++++++++--- public/scripts/tags.js | 22 +++++++++++++++++----- src/endpoints/characters.js | 2 +- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/public/script.js b/public/script.js index 59e7995f1..d904d1ab7 100644 --- a/public/script.js +++ b/public/script.js @@ -172,6 +172,7 @@ import { importTags, tag_filter_types, compareTagsForSort, + initTags, } from './scripts/tags.js'; import { SECRET_KEYS, @@ -412,6 +413,7 @@ export const event_types = { CHARACTER_FIRST_MESSAGE_SELECTED: 'character_first_message_selected', // TODO: Naming convention is inconsistent with other events CHARACTER_DELETED: 'characterDeleted', + CHARACTER_DUPLICATED: 'character_duplicated', }; export const eventSource = new EventEmitter(); @@ -864,6 +866,7 @@ async function firstLoadInit() { getSystemMessages(); sendSystemMessage(system_message_types.WELCOME); initLocales(); + initTags(); await getUserAvatars(true, user_avatar); await getCharacters(); await getBackgrounds(); @@ -4323,6 +4326,8 @@ async function DupeChar() { }); if (response.ok) { toastr.success('Character Duplicated'); + const data = await response.json(); + await eventSource.emit(event_types.CHARACTER_DUPLICATED, { oldAvatar: body.avatar_url, newAvatar: data.path }); getCharacters(); } } diff --git a/public/scripts/BulkEditOverlay.js b/public/scripts/BulkEditOverlay.js index eb69f279b..d8f2f17cb 100644 --- a/public/scripts/BulkEditOverlay.js +++ b/public/scripts/BulkEditOverlay.js @@ -48,16 +48,24 @@ class CharacterContextMenu { * Duplicate one or more characters * * @param characterId - * @returns {Promise} + * @returns {Promise} */ static duplicate = async (characterId) => { const character = CharacterContextMenu.#getCharacter(characterId); + const body = { avatar_url: character.avatar }; - return fetch('/api/characters/duplicate', { + const result = await fetch('/api/characters/duplicate', { method: 'POST', headers: getRequestHeaders(), - body: JSON.stringify({ avatar_url: character.avatar }), + body: JSON.stringify(), }); + + if (!result.ok) { + throw new Error('Character not duplicated'); + } + + const data = await result.json(); + await eventSource.emit(event_types.CHARACTER_DUPLICATED, { oldAvatar: body.avatar_url, newAvatar: data.path }); }; /** diff --git a/public/scripts/tags.js b/public/scripts/tags.js index 2615d87b3..a995a52f2 100644 --- a/public/scripts/tags.js +++ b/public/scripts/tags.js @@ -8,6 +8,8 @@ import { entitiesFilter, printCharacters, buildAvatarList, + eventSource, + event_types, } from '../script.js'; // eslint-disable-next-line no-unused-vars import { FILTER_TYPES, FILTER_STATES, isFilterState, FilterHelper } from './filters.js'; @@ -132,7 +134,7 @@ function filterByTagState(entities, { globalDisplayFilters = false, subForEntity } if (subForEntity !== undefined && subForEntity.type === 'tag') { - entities = filterTagSubEntities(subForEntity.item, entities, { filterHidden : filterHidden }); + entities = filterTagSubEntities(subForEntity.item, entities, { filterHidden: filterHidden }); } return entities; @@ -1140,7 +1142,7 @@ function onClearAllFiltersClick() { // We have to manually go through the elements and unfilter by clicking... // Thankfully nearly all filter controls are three-state-toggles const filterTags = $('.rm_tag_controls .rm_tag_filter').find('.tag'); - for(const tag of filterTags) { + for (const tag of filterTags) { const toggleState = $(tag).attr('data-toggle-state'); if (toggleState !== undefined && !isFilterState(toggleState ?? FILTER_STATES.UNDEFINED, FILTER_STATES.UNDEFINED)) { toggleTagThreeState($(tag), { stateOverride: FILTER_STATES.UNDEFINED, simulateClick: true }); @@ -1151,7 +1153,17 @@ function onClearAllFiltersClick() { $('#character_search_bar').val('').trigger('input'); } -jQuery(() => { +/** + * Copy tags from one character to another. + * @param {{oldAvatar: string, newAvatar: string}} data Event data + */ +function copyTags(data) { + const prevTagMap = tag_map[data.oldAvatar] || []; + const newTagMap = tag_map[data.newAvatar] || []; + tag_map[data.newAvatar] = Array.from(new Set([...prevTagMap, ...newTagMap])); +} + +export function initTags() { createTagInput('#tagInput', '#tagList'); createTagInput('#groupTagInput', '#groupTagList'); @@ -1168,5 +1180,5 @@ jQuery(() => { $(document).on('click', '.tag_view_create', onTagCreateClick); $(document).on('click', '.tag_view_backup', onTagsBackupClick); $(document).on('click', '.tag_view_restore', onBackupRestoreClick); -}); - + eventSource.on(event_types.CHARACTER_DUPLICATED, copyTags); +} diff --git a/src/endpoints/characters.js b/src/endpoints/characters.js index e2063def3..613f88c79 100644 --- a/src/endpoints/characters.js +++ b/src/endpoints/characters.js @@ -1008,7 +1008,7 @@ router.post('/duplicate', jsonParser, async function (request, response) { fs.copyFileSync(filename, newFilename); console.log(`${filename} was copied to ${newFilename}`); - response.sendStatus(200); + response.send({ path: path.parse(newFilename).base }); } catch (error) { console.error(error); From 6ca2111ef61e2458cf9d5dfed9d1ebcfd864b3c5 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 28 Mar 2024 01:15:14 +0200 Subject: [PATCH 4/7] Honey I broke mass duplicator --- public/scripts/BulkEditOverlay.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/BulkEditOverlay.js b/public/scripts/BulkEditOverlay.js index d8f2f17cb..50a2ba478 100644 --- a/public/scripts/BulkEditOverlay.js +++ b/public/scripts/BulkEditOverlay.js @@ -57,7 +57,7 @@ class CharacterContextMenu { const result = await fetch('/api/characters/duplicate', { method: 'POST', headers: getRequestHeaders(), - body: JSON.stringify(), + body: JSON.stringify(body), }); if (!result.ok) { From 03d255442e921109a196933eca063a779fe8b2c4 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 28 Mar 2024 01:17:43 +0200 Subject: [PATCH 5/7] Return display avatar name on hover --- public/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index d904d1ab7..5025242eb 100644 --- a/public/script.js +++ b/public/script.js @@ -1240,7 +1240,7 @@ function getCharacterBlock(item, id) { const template = $('#character_template .character_select').clone(); template.attr({ 'chid': id, 'id': `CharID${id}` }); template.find('img').attr('src', this_avatar).attr('alt', item.name); - template.find('.avatar').attr('title', `[Character] ${item.name}`); + template.find('.avatar').attr('title', `[Character] ${item.name}\n${item.avatar}`); template.find('.ch_name').text(item.name).attr('title', `[Character] ${item.name}`); if (power_user.show_card_avatar_urls) { template.find('.ch_avatar_url').text(item.avatar); From 945e3e3b0ea98f0f21a20c23e275ebea4359f655 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 28 Mar 2024 01:27:28 +0200 Subject: [PATCH 6/7] Add prefix to avatar tooltip --- public/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index 5025242eb..36539cc9a 100644 --- a/public/script.js +++ b/public/script.js @@ -1240,7 +1240,7 @@ function getCharacterBlock(item, id) { const template = $('#character_template .character_select').clone(); template.attr({ 'chid': id, 'id': `CharID${id}` }); template.find('img').attr('src', this_avatar).attr('alt', item.name); - template.find('.avatar').attr('title', `[Character] ${item.name}\n${item.avatar}`); + template.find('.avatar').attr('title', `[Character] ${item.name}\nFile: ${item.avatar}`); template.find('.ch_name').text(item.name).attr('title', `[Character] ${item.name}`); if (power_user.show_card_avatar_urls) { template.find('.ch_avatar_url').text(item.avatar); From 4a71bda1dcbf92679b1dcfbb4cb0ebdf9ca7547d Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 28 Mar 2024 01:28:41 +0200 Subject: [PATCH 7/7] Bit tighter character panel layout --- public/index.html | 8 ++++---- public/style.css | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/public/index.html b/public/index.html index baf5c2d3d..03fd07a4c 100644 --- a/public/index.html +++ b/public/index.html @@ -4110,7 +4110,7 @@
- +
@@ -4130,7 +4130,7 @@