From 53848e1b0d97c60df7a38749d9590d6223300de6 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Wed, 27 Mar 2024 09:49:59 +0100 Subject: [PATCH 1/2] Persona retrigger first message consistency fix --- public/script.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/public/script.js b/public/script.js index 38ed270cd..61a139231 100644 --- a/public/script.js +++ b/public/script.js @@ -5720,6 +5720,9 @@ export function setUserName(value) { toastr.success(`Your messages will now be sent as ${name1}`, 'Current persona updated'); } saveSettingsDebounced(); + + // force firstMes {{user}} update on persona switch + retriggerFirstMessageOnEmptychat(); } /** @@ -5733,6 +5736,15 @@ export function setUserAvatar(imgfile) { selectCurrentPersona(); saveSettingsDebounced(); $('.zoomed_avatar[forchar]').remove(); + + // force firstMes {{user}} update on persona switch + retriggerFirstMessageOnEmptychat(); +} + +function retriggerFirstMessageOnEmptychat() { + if (this_chid >= 0 && !selected_group && chat.length === 1) { + $('#firstmessage_textarea').trigger('input'); + } } async function uploadUserAvatar(e) { @@ -8467,11 +8479,6 @@ jQuery(async function () { $(document).on('click', '#user_avatar_block .avatar-container', function () { const imgfile = $(this).attr('imgfile'); setUserAvatar(imgfile); - - // force firstMes {{user}} update on persona switch - if (this_chid >= 0 && !selected_group && chat.length === 1) { - $('#firstmessage_textarea').trigger('input'); - } }); $(document).on('click', '#user_avatar_block .avatar_upload', function () { $('#avatar_upload_overwrite').val(''); From 6d02223bd49977216b87b94660360d8c1ded8f97 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:16:20 +0200 Subject: [PATCH 2/2] Fix cases with persona autoswitch --- public/script.js | 12 +++++------- public/scripts/slash-commands.js | 3 +++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/public/script.js b/public/script.js index 61a139231..e56f4ec33 100644 --- a/public/script.js +++ b/public/script.js @@ -5720,9 +5720,6 @@ export function setUserName(value) { toastr.success(`Your messages will now be sent as ${name1}`, 'Current persona updated'); } saveSettingsDebounced(); - - // force firstMes {{user}} update on persona switch - retriggerFirstMessageOnEmptychat(); } /** @@ -5736,12 +5733,9 @@ export function setUserAvatar(imgfile) { selectCurrentPersona(); saveSettingsDebounced(); $('.zoomed_avatar[forchar]').remove(); - - // force firstMes {{user}} update on persona switch - retriggerFirstMessageOnEmptychat(); } -function retriggerFirstMessageOnEmptychat() { +export function retriggerFirstMessageOnEmptyChat() { if (this_chid >= 0 && !selected_group && chat.length === 1) { $('#firstmessage_textarea').trigger('input'); } @@ -8479,6 +8473,9 @@ jQuery(async function () { $(document).on('click', '#user_avatar_block .avatar-container', function () { const imgfile = $(this).attr('imgfile'); setUserAvatar(imgfile); + + // force firstMes {{user}} update on persona switch + retriggerFirstMessageOnEmptyChat(); }); $(document).on('click', '#user_avatar_block .avatar_upload', function () { $('#avatar_upload_overwrite').val(''); @@ -9582,6 +9579,7 @@ jQuery(async function () { const userName = String($('#your_name').val()).trim(); setUserName(userName); await updatePersonaNameIfExists(user_avatar, userName); + retriggerFirstMessageOnEmptyChat(); }); $('#sync_name_button').on('click', async function () { diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 76d4b11db..a6e0020ef 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -22,6 +22,7 @@ import { name1, reloadCurrentChat, removeMacros, + retriggerFirstMessageOnEmptyChat, saveChatConditional, sendMessageAsUser, sendSystemMessage, @@ -1340,12 +1341,14 @@ function setNameCallback(_, name) { for (let persona of Object.values(power_user.personas)) { if (persona.toLowerCase() === name.toLowerCase()) { autoSelectPersona(name); + retriggerFirstMessageOnEmptyChat(); return; } } // Otherwise, set just the name setUserName(name); //this prevented quickReply usage + retriggerFirstMessageOnEmptyChat(); } async function setNarratorName(_, text) {