Only navigate to persona if switched by connection

90be2eee717e18a4e2a88b28954a51853db8d457

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +8 -5Ignore whitespace
public/scripts/personas.js+8 -5
@@ -26,7 +26,7 @@ import { PAGINATION_TEMPLATE, clearInfoBlock, debounce, delay, download, ensureI
26import { debounce_timeout } from './constants.js';26import { debounce_timeout } from './constants.js';
27import { FILTER_TYPES, FilterHelper } from './filters.js';27import { FILTER_TYPES, FilterHelper } from './filters.js';
28import { groups, selected_group } from './group-chats.js';28import { groups, selected_group } from './group-chats.js';
29import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js';29import { POPUP_TYPE, Popup, callGenericPopup } from './popup.js';
30import { t } from './i18n.js';30import { t } from './i18n.js';
31import { openWorldInfoEditor, world_names } from './world-info.js';31import { openWorldInfoEditor, world_names } from './world-info.js';
32import { renderTemplateAsync } from './templates.js';32import { renderTemplateAsync } from './templates.js';
@@ -102,11 +102,14 @@ export function initUserAvatar(avatar) {
102/**102/**
103 * Sets a user avatar file103 * Sets a user avatar file
104 * @param {string} imgfile Link to an image file104 * @param {string} imgfile Link to an image file
105 * @param {object} [options] Optional settings
106 * @param {boolean} [options.toastPersonaNameChange=true] Whether to show a toast when the persona name is changed
107 * @param {boolean} [options.navigateToCurrent=false] Whether to navigate to the current persona after setting the avatar
105 */108 */
106export function setUserAvatar(imgfile, { toastPersonaNameChange = true } = {}) {109export function setUserAvatar(imgfile, { toastPersonaNameChange = true, navigateToCurrent = false } = {}) {
107 user_avatar = imgfile && typeof imgfile === 'string' ? imgfile : $(this).attr('data-avatar-id');110 user_avatar = imgfile && typeof imgfile === 'string' ? imgfile : $(this).attr('data-avatar-id');
108 reloadUserAvatar();111 reloadUserAvatar();
109 updatePersonaUIStates();112 updatePersonaUIStates({ navigateToCurrent: navigateToCurrent });
110 selectCurrentPersona({ toastPersonaNameChange: toastPersonaNameChange });113 selectCurrentPersona({ toastPersonaNameChange: toastPersonaNameChange });
111 saveSettingsDebounced();114 saveSettingsDebounced();
112 $('.zoomed_avatar[forchar]').remove();115 $('.zoomed_avatar[forchar]').remove();
@@ -1451,7 +1454,7 @@ async function loadPersonaForCurrentChat({ doRender = false } = {}) {
1451 // Persona avatar found, select it1454 // Persona avatar found, select it
1452 if (chatPersona && user_avatar !== chatPersona) {1455 if (chatPersona && user_avatar !== chatPersona) {
1453 const willAutoLock = power_user.persona_auto_lock && user_avatar !== chat_metadata['persona'];1456 const willAutoLock = power_user.persona_auto_lock && user_avatar !== chat_metadata['persona'];
1454 setUserAvatar(chatPersona, { toastPersonaNameChange: false });1457 setUserAvatar(chatPersona, { toastPersonaNameChange: false, navigateToCurrent: true });
14551458
1456 if (power_user.persona_show_notifications) {1459 if (power_user.persona_show_notifications) {
1457 let message = t`Auto-selected persona based on ${connectType} connection.<br />Your messages will now be sent as ${power_user.personas[chatPersona]}.`;1460 let message = t`Auto-selected persona based on ${connectType} connection.<br />Your messages will now be sent as ${power_user.personas[chatPersona]}.`;
@@ -1462,7 +1465,7 @@ async function loadPersonaForCurrentChat({ doRender = false } = {}) {
1462 }1465 }
1463 }1466 }
14641467
1465 updatePersonaUIStates({ navigateToCurrent: true });1468 updatePersonaUIStates();
14661469
1467 return !!chatPersona;1470 return !!chatPersona;
1468}1471}