Only navigate to persona if switched by connection
| @@ -26,7 +26,7 @@ import { PAGINATION_TEMPLATE, clearInfoBlock, debounce, delay, download, ensureI | |||
| 26 | import { debounce_timeout } from './constants.js'; | 26 | import { debounce_timeout } from './constants.js'; |
| 27 | import { FILTER_TYPES, FilterHelper } from './filters.js'; | 27 | import { FILTER_TYPES, FilterHelper } from './filters.js'; |
| 28 | import { groups, selected_group } from './group-chats.js'; | 28 | import { groups, selected_group } from './group-chats.js'; |
| 29 | import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup } from './popup.js'; | 29 | import { POPUP_TYPE, Popup, callGenericPopup } from './popup.js'; |
| 30 | import { t } from './i18n.js'; | 30 | import { t } from './i18n.js'; |
| 31 | import { openWorldInfoEditor, world_names } from './world-info.js'; | 31 | import { openWorldInfoEditor, world_names } from './world-info.js'; |
| 32 | import { renderTemplateAsync } from './templates.js'; | 32 | import { renderTemplateAsync } from './templates.js'; |
| @@ -102,11 +102,14 @@ export function initUserAvatar(avatar) { | |||
| 102 | /** | 102 | /** |
| 103 | * Sets a user avatar file | 103 | * Sets a user avatar file |
| 104 | * @param {string} imgfile Link to an image file | 104 | * @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 | */ |
| 106 | export function setUserAvatar(imgfile, { toastPersonaNameChange = true } = {}) { | 109 | export 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 it | 1454 | // 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 }); |
| 1455 | 1458 | ||
| 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 | } |
| 1464 | 1467 | ||
| 1465 | updatePersonaUIStates({ navigateToCurrent: true }); | 1468 | updatePersonaUIStates(); |
| 1466 | 1469 | ||
| 1467 | return !!chatPersona; | 1470 | return !!chatPersona; |
| 1468 | } | 1471 | } |