Fix cases with persona autoswitch

This commit is contained in:
Cohee
2024-03-27 15:16:20 +02:00
parent 53848e1b0d
commit 6d02223bd4
2 changed files with 8 additions and 7 deletions

View File

@ -5720,9 +5720,6 @@ export function setUserName(value) {
toastr.success(`Your messages will now be sent as ${name1}`, 'Current persona updated'); toastr.success(`Your messages will now be sent as ${name1}`, 'Current persona updated');
} }
saveSettingsDebounced(); saveSettingsDebounced();
// force firstMes {{user}} update on persona switch
retriggerFirstMessageOnEmptychat();
} }
/** /**
@ -5736,12 +5733,9 @@ export function setUserAvatar(imgfile) {
selectCurrentPersona(); selectCurrentPersona();
saveSettingsDebounced(); saveSettingsDebounced();
$('.zoomed_avatar[forchar]').remove(); $('.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) { if (this_chid >= 0 && !selected_group && chat.length === 1) {
$('#firstmessage_textarea').trigger('input'); $('#firstmessage_textarea').trigger('input');
} }
@ -8479,6 +8473,9 @@ jQuery(async function () {
$(document).on('click', '#user_avatar_block .avatar-container', function () { $(document).on('click', '#user_avatar_block .avatar-container', function () {
const imgfile = $(this).attr('imgfile'); const imgfile = $(this).attr('imgfile');
setUserAvatar(imgfile); setUserAvatar(imgfile);
// force firstMes {{user}} update on persona switch
retriggerFirstMessageOnEmptyChat();
}); });
$(document).on('click', '#user_avatar_block .avatar_upload', function () { $(document).on('click', '#user_avatar_block .avatar_upload', function () {
$('#avatar_upload_overwrite').val(''); $('#avatar_upload_overwrite').val('');
@ -9582,6 +9579,7 @@ jQuery(async function () {
const userName = String($('#your_name').val()).trim(); const userName = String($('#your_name').val()).trim();
setUserName(userName); setUserName(userName);
await updatePersonaNameIfExists(user_avatar, userName); await updatePersonaNameIfExists(user_avatar, userName);
retriggerFirstMessageOnEmptyChat();
}); });
$('#sync_name_button').on('click', async function () { $('#sync_name_button').on('click', async function () {

View File

@ -22,6 +22,7 @@ import {
name1, name1,
reloadCurrentChat, reloadCurrentChat,
removeMacros, removeMacros,
retriggerFirstMessageOnEmptyChat,
saveChatConditional, saveChatConditional,
sendMessageAsUser, sendMessageAsUser,
sendSystemMessage, sendSystemMessage,
@ -1340,12 +1341,14 @@ function setNameCallback(_, name) {
for (let persona of Object.values(power_user.personas)) { for (let persona of Object.values(power_user.personas)) {
if (persona.toLowerCase() === name.toLowerCase()) { if (persona.toLowerCase() === name.toLowerCase()) {
autoSelectPersona(name); autoSelectPersona(name);
retriggerFirstMessageOnEmptyChat();
return; return;
} }
} }
// Otherwise, set just the name // Otherwise, set just the name
setUserName(name); //this prevented quickReply usage setUserName(name); //this prevented quickReply usage
retriggerFirstMessageOnEmptyChat();
} }
async function setNarratorName(_, text) { async function setNarratorName(_, text) {