Reduce persona toast spam

1f116d9afe9aa5bf9401b570c07cf03818c1aab8

Wolfsblvt <wolfsblvt@gmail.com>

2 files changed, +28 -25Ignore whitespace
public/script.js+5 -5
@@ -6737,14 +6737,14 @@ export function changeMainAPI() {
6737 forceCharacterEditorTokenize();6737 forceCharacterEditorTokenize();
6738}6738}
67396739
6740export function setUserName(value) {6740export function setUserName(value, { toastPersonaNameChange = true } = {}) {
6741 name1 = value;6741 name1 = value;
6742 if (name1 === undefined || name1 == '')6742 if (name1 === undefined || name1 == '')
6743 name1 = default_user_name;6743 name1 = default_user_name;
6744 console.log(`User name changed to ${name1}`);6744 console.log(`User name changed to ${name1}`);
6745 $('#your_name').val(name1);6745 $('#your_name').val(name1);
6746 if (power_user.persona_show_notifications) {6746 if (toastPersonaNameChange && power_user.persona_show_notifications) {
6747 toastr.success(t`Your messages will now be sent as ${name1}`, t`Current persona updated`);6747 toastr.success(t`Your messages will now be sent as ${name1}`, t`Persona Changed`);
6748 }6748 }
6749 saveSettingsDebounced();6749 saveSettingsDebounced();
6750}6750}
@@ -10024,9 +10024,9 @@ jQuery(async function () {
1002410024
10025 // One of the persona was selected. So load it.10025 // One of the persona was selected. So load it.
10026 if (!isRemoving && selectedPersona) {10026 if (!isRemoving && selectedPersona) {
10027 setUserAvatar(selectedPersona);10027 setUserAvatar(selectedPersona, { toastPersonaNameChange: false });
10028 if (power_user.persona_show_notifications) {10028 if (power_user.persona_show_notifications) {
10029 toastr.info(t`Selected persona ${power_user.personas[selectedPersona]} for current chat.`, t`Connected Persona Selected`);10029 toastr.success(t`Selected persona ${power_user.personas[selectedPersona]} for current chat.`, t`Connected Persona Selected`);
10030 }10030 }
10031 }10031 }
10032 });10032 });
public/scripts/personas.js+23 -20
@@ -73,11 +73,11 @@ export function initUserAvatar(avatar) {
73 * Sets a user avatar file73 * Sets a user avatar file
74 * @param {string} imgfile Link to an image file74 * @param {string} imgfile Link to an image file
75 */75 */
76export function setUserAvatar(imgfile) {76export function setUserAvatar(imgfile, { toastPersonaNameChange = true } = {}) {
77 user_avatar = imgfile && typeof imgfile === 'string' ? imgfile : $(this).attr('imgfile');77 user_avatar = imgfile && typeof imgfile === 'string' ? imgfile : $(this).attr('imgfile');
78 reloadUserAvatar();78 reloadUserAvatar();
79 highlightSelectedAvatar();79 highlightSelectedAvatar();
80 selectCurrentPersona();80 selectCurrentPersona({ toastPersonaNameChange: toastPersonaNameChange });
81 saveSettingsDebounced();81 saveSettingsDebounced();
82 $('.zoomed_avatar[forchar]').remove();82 $('.zoomed_avatar[forchar]').remove();
83}83}
@@ -628,7 +628,7 @@ export async function askForPersonaSelection(title, text, personas, { okButton =
628 updatePersonaConnectionsAvatarList();628 updatePersonaConnectionsAvatarList();
629 if (power_user.persona_show_notifications) {629 if (power_user.persona_show_notifications) {
630 const name = targetedChar.type == 'character' ? characters[targetedChar.id]?.name : groups[targetedChar.id]?.name;630 const name = targetedChar.type == 'character' ? characters[targetedChar.id]?.name : groups[targetedChar.id]?.name;
631 toastr.info(t`All connections to ${name} have been removed.`, t`Personas unlocked`);631 toastr.info(t`All connections to ${name} have been removed.`, t`Personas Unlocked`);
632 }632 }
633 },633 },
634 });634 });
@@ -732,12 +732,14 @@ async function bindUserNameToPersona(e) {
732 setPersonaDescription();732 setPersonaDescription();
733}733}
734734
735function selectCurrentPersona() {735function selectCurrentPersona({ toastPersonaNameChange = true } = {}) {
736 const personaName = power_user.personas[user_avatar];736 const personaName = power_user.personas[user_avatar];
737 if (personaName) {737 if (personaName) {
738 const shouldAutoLock = power_user.persona_auto_lock && user_avatar !== chat_metadata['persona'];
739
738 if (personaName !== name1) {740 if (personaName !== name1) {
739 console.log(`Auto-updating user name to ${personaName}`);741 console.log(`Auto-updating user name to ${personaName}`);
740 setUserName(personaName);742 setUserName(personaName, { toastPersonaNameChange: !shouldAutoLock && toastPersonaNameChange });
741 }743 }
742744
743 const descriptor = power_user.persona_descriptions[user_avatar];745 const descriptor = power_user.persona_descriptions[user_avatar];
@@ -767,11 +769,11 @@ function selectCurrentPersona() {
767 setPersonaDescription();769 setPersonaDescription();
768770
769 // Update the locked persona if setting is enabled771 // Update the locked persona if setting is enabled
770 if (power_user.persona_auto_lock && personaName && user_avatar !== chat_metadata['persona']) {772 if (shouldAutoLock) {
771 chat_metadata['persona'] = user_avatar;773 chat_metadata['persona'] = user_avatar;
772 console.log(`Auto locked persona to ${user_avatar}`);774 console.log(`Auto locked persona to ${user_avatar}`);
773 if (power_user.persona_show_notifications) {775 if (toastPersonaNameChange && power_user.persona_show_notifications) {
774 toastr.info(`Auto locked persona ${personaName} to current chat`, t`Persona Auto Lock`);776 toastr.success(`Persona ${personaName} selected and auto-locked to current chat`, t`Persona Selected`);
775 }777 }
776 saveMetadataDebounced();778 saveMetadataDebounced();
777 updatePersonaLockIcons();779 updatePersonaLockIcons();
@@ -788,7 +790,7 @@ function selectCurrentPersona() {
788 + t`Current Persona: ${power_user.personas[user_avatar]}`790 + t`Current Persona: ${power_user.personas[user_avatar]}`
789 + (hasDifferentChatLock ? '<br />' + t`Chat persona: ${power_user.personas[chat_metadata['persona']]}` : '')791 + (hasDifferentChatLock ? '<br />' + t`Chat persona: ${power_user.personas[chat_metadata['persona']]}` : '')
790 + (hasDifferentDefaultLock ? '<br />' + t`Default persona: ${power_user.personas[power_user.default_persona]}` : '');792 + (hasDifferentDefaultLock ? '<br />' + t`Default persona: ${power_user.personas[power_user.default_persona]}` : '');
791 toastr.info(message, t`Temporary Persona`, { escapeHtml: false, timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });793 toastr.info(message, t`Temporary Persona`, { escapeHtml: false, preventDuplicates: true });
792 }794 }
793 }795 }
794 }796 }
@@ -865,7 +867,7 @@ async function unlockPersona(type = 'chat') {
865 delete chat_metadata['persona'];867 delete chat_metadata['persona'];
866 await saveMetadata();868 await saveMetadata();
867 if (power_user.persona_show_notifications) {869 if (power_user.persona_show_notifications) {
868 toastr.info(t`User persona ${name1} is now unlocked from this chat. Click the "Lock" again to revert.`, t`Persona unlocked`);870 toastr.info(t`Persona ${name1} is now unlocked from this chat.`, t`Persona Unlocked`);
869 }871 }
870 }872 }
871 break;873 break;
@@ -879,7 +881,7 @@ async function unlockPersona(type = 'chat') {
879 saveSettingsDebounced();881 saveSettingsDebounced();
880 updatePersonaConnectionsAvatarList();882 updatePersonaConnectionsAvatarList();
881 if (power_user.persona_show_notifications) {883 if (power_user.persona_show_notifications) {
882 toastr.info(t`User persona ${name1} is now unlocked from character ${name2}. Click the "Lock" again to revert.`, t`Persona unlocked`);884 toastr.info(t`Persona ${name1} is now unlocked from character ${name2}.`, t`Persona Unlocked`);
883 }885 }
884 }886 }
885 break;887 break;
@@ -900,11 +902,7 @@ async function lockPersona(type = 'chat') {
900 if (!(user_avatar in power_user.personas)) {902 if (!(user_avatar in power_user.personas)) {
901 console.log(`Creating a new persona ${user_avatar}`);903 console.log(`Creating a new persona ${user_avatar}`);
902 if (power_user.persona_show_notifications) {904 if (power_user.persona_show_notifications) {
903 toastr.info(905 toastr.info(t`Creating a new persona for currently selected user name and avatar...`, t`Persona Not Found`);
904 t`Creating a new persona for currently selected user name and avatar...`,
905 t`Persona Does Not Exist`,
906 { timeOut: 10000, extendedTimeOut: 20000 },
907 );
908 }906 }
909 power_user.personas[user_avatar] = name1;907 power_user.personas[user_avatar] = name1;
910 power_user.persona_descriptions[user_avatar] = {908 power_user.persona_descriptions[user_avatar] = {
@@ -1211,7 +1209,7 @@ async function toggleDefaultPersona(avatarId, { quiet: quiet = false } = {}) {
12111209
1212 power_user.default_persona = avatarId;1210 power_user.default_persona = avatarId;
1213 if (power_user.persona_show_notifications) {1211 if (power_user.persona_show_notifications) {
1214 toastr.success(t`Set to ${power_user.personas[avatarId]}.This persona will be used by default when you open a new chat.`, t`Default Persona Set`);1212 toastr.success(t`Set to ${power_user.personas[avatarId]}.This persona will be used by default when you open a new chat.`, t`Default Persona`);
1215 }1213 }
1216 }1214 }
12171215
@@ -1272,8 +1270,8 @@ async function loadPersonaForCurrentChat() {
1272 if (connectedPersonas.length === 1) {1270 if (connectedPersonas.length === 1) {
1273 chatPersona = connectedPersonas[0];1271 chatPersona = connectedPersonas[0];
1274 } else if (!power_user.persona_allow_multi_connections) {1272 } else if (!power_user.persona_allow_multi_connections) {
1273 console.warn('More than one persona is connected to this character.Using the first available persona for this chat.');
1275 chatPersona = connectedPersonas[0];1274 chatPersona = connectedPersonas[0];
1276 toastr.warning(t`More than one persona is connected to this character. Using the first available persona for this chat.`, t`Automatic Persona Selection`);
1277 } else {1275 } else {
1278 chatPersona = await askForPersonaSelection(t`Select Persona`,1276 chatPersona = await askForPersonaSelection(t`Select Persona`,
1279 t`Multiple personas are connected to this character.\nSelect a persona to use for this chat.`,1277 t`Multiple personas are connected to this character.\nSelect a persona to use for this chat.`,
@@ -1307,10 +1305,15 @@ async function loadPersonaForCurrentChat() {
13071305
1308 // Persona avatar found, select it1306 // Persona avatar found, select it
1309 if (chatPersona) {1307 if (chatPersona) {
1310 setUserAvatar(chatPersona);1308 const willAutoLock = power_user.persona_auto_lock && user_avatar !== chat_metadata['persona'];
1309 setUserAvatar(chatPersona, { toastPersonaNameChange: false });
13111310
1312 if (power_user.persona_show_notifications) {1311 if (power_user.persona_show_notifications) {
1313 toastr.info(t`Auto-selected persona ${power_user.personas[chatPersona]} based on ${connectType} connection.`, t`Persona Auto Selected`);1312 let message = t`Auto-selected persona based on ${connectType} connection.<br />Your messages will now be sent as ${power_user.personas[chatPersona]}.`;
1313 if (willAutoLock) {
1314 message += '<br /><br />' + t`Auto-locked this persona to current chat.`;
1315 }
1316 toastr.success(message, t`Persona Auto Selected`, { escapeHtml: false });
1314 }1317 }
1315 }1318 }
13161319