Centralize first message retrigger on persona changes

Moves retrigger logic to setUserAvatar entry point
to avoid duplicate calls when updating personas
Removes redundant triggers from name/avatar handlers

Fixes #3774
This commit is contained in:
Wolfsblvt
2025-03-28 01:28:36 +01:00
parent 6dc33e9637
commit d95524032e

View File

@@ -111,6 +111,7 @@ export function setUserAvatar(imgfile, { toastPersonaNameChange = true, navigate
reloadUserAvatar(); reloadUserAvatar();
updatePersonaUIStates({ navigateToCurrent: navigateToCurrent }); updatePersonaUIStates({ navigateToCurrent: navigateToCurrent });
selectCurrentPersona({ toastPersonaNameChange: toastPersonaNameChange }); selectCurrentPersona({ toastPersonaNameChange: toastPersonaNameChange });
retriggerFirstMessageOnEmptyChat();
saveSettingsDebounced(); saveSettingsDebounced();
$('.zoomed_avatar[forchar]').remove(); $('.zoomed_avatar[forchar]').remove();
} }
@@ -1782,7 +1783,6 @@ function setNameCallback({ mode = 'all' }, name) {
if (!persona) persona = Object.entries(power_user.personas).find(([_, personaName]) => personaName.toLowerCase() === name.toLowerCase())?.[1]; if (!persona) persona = Object.entries(power_user.personas).find(([_, personaName]) => personaName.toLowerCase() === name.toLowerCase())?.[1];
if (persona) { if (persona) {
autoSelectPersona(persona); autoSelectPersona(persona);
retriggerFirstMessageOnEmptyChat();
return ''; return '';
} else if (mode === 'lookup') { } else if (mode === 'lookup') {
toastr.warning(`Persona ${name} not found`); toastr.warning(`Persona ${name} not found`);
@@ -1793,7 +1793,6 @@ function setNameCallback({ mode = 'all' }, name) {
if (['temp', 'all'].includes(mode)) { if (['temp', 'all'].includes(mode)) {
// Otherwise, set just the name // Otherwise, set just the name
setUserName(name); //this prevented quickReply usage setUserName(name); //this prevented quickReply usage
retriggerFirstMessageOnEmptyChat();
} }
return ''; return '';
@@ -1944,9 +1943,6 @@ export async function initPersonas() {
$(document).on('click', '#user_avatar_block .avatar-container', function () { $(document).on('click', '#user_avatar_block .avatar-container', function () {
const imgfile = $(this).attr('data-avatar-id'); const imgfile = $(this).attr('data-avatar-id');
setUserAvatar(imgfile); setUserAvatar(imgfile);
// force firstMes {{user}} update on persona switch
retriggerFirstMessageOnEmptyChat();
}); });
$('#persona_rename_button').on('click', () => renamePersona(user_avatar)); $('#persona_rename_button').on('click', () => renamePersona(user_avatar));