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() {
67376737 forceCharacterEditorTokenize();
67386738}
67396739
67406740export function setUserName(value, { toastPersonaNameChange = true } = {}) {
67416741 name1 = value;
67426742 if (name1 === undefined || name1 == '')
67436743 name1 = default_user_name;
67446744 console.log(`User name changed to ${name1}`);
67456745 $('#your_name').val(name1);
67466746 if (toastPersonaNameChange && power_user.persona_show_notifications) {
67476747 toastr.success(t`Your messages will now be sent as ${name1}`, t`Current personaPersona updatedChanged`);
67486748 }
67496749 saveSettingsDebounced();
67506750}
@@ -10024,9 +10024,9 @@ jQuery(async function () {
1002410024
1002510025 // One of the persona was selected. So load it.
1002610026 if (!isRemoving && selectedPersona) {
1002710027 setUserAvatar(selectedPersona, { toastPersonaNameChange: false });
1002810028 if (power_user.persona_show_notifications) {
1002910029 toastr.infosuccess(t`Selected persona ${power_user.personas[selectedPersona]} for current chat.`, t`Connected Persona Selected`);
1003010030 }
1003110031 }
1003210032 });
public/scripts/personas.js+23 -20
@@ -73,11 +73,11 @@ export function initUserAvatar(avatar) {
7373 * Sets a user avatar file
7474 * @param {string} imgfile Link to an image file
7575 */
7676export function setUserAvatar(imgfile, { toastPersonaNameChange = true } = {}) {
7777 user_avatar = imgfile && typeof imgfile === 'string' ? imgfile : $(this).attr('imgfile');
7878 reloadUserAvatar();
7979 highlightSelectedAvatar();
8080 selectCurrentPersona({ toastPersonaNameChange: toastPersonaNameChange });
8181 saveSettingsDebounced();
8282 $('.zoomed_avatar[forchar]').remove();
8383}
@@ -628,7 +628,7 @@ export async function askForPersonaSelection(title, text, personas, { okButton =
628628 updatePersonaConnectionsAvatarList();
629629 if (power_user.persona_show_notifications) {
630630 const name = targetedChar.type == 'character' ? characters[targetedChar.id]?.name : groups[targetedChar.id]?.name;
631631 toastr.info(t`All connections to ${name} have been removed.`, t`Personas unlockedUnlocked`);
632632 }
633633 },
634634 });
@@ -732,12 +732,14 @@ async function bindUserNameToPersona(e) {
732732 setPersonaDescription();
733733}
734734
735735function selectCurrentPersona({ toastPersonaNameChange = true } = {}) {
736736 const personaName = power_user.personas[user_avatar];
737737 if (personaName) {
738+ const shouldAutoLock = power_user.persona_auto_lock && user_avatar !== chat_metadata['persona'];
739+
738740 if (personaName !== name1) {
739741 console.log(`Auto-updating user name to ${personaName}`);
740- setUserName(personaName);
742+ setUserName(personaName, { toastPersonaNameChange: !shouldAutoLock && toastPersonaNameChange });
741743 }
742744
743745 const descriptor = power_user.persona_descriptions[user_avatar];
@@ -767,11 +769,11 @@ function selectCurrentPersona() {
767769 setPersonaDescription();
768770
769771 // Update the locked persona if setting is enabled
770- if (power_user.persona_auto_lock && personaName && user_avatar !== chat_metadata['persona']) {
772+ if (shouldAutoLock) {
771773 chat_metadata['persona'] = user_avatar;
772774 console.log(`Auto locked persona to ${user_avatar}`);
773775 if (toastPersonaNameChange && power_user.persona_show_notifications) {
774776 toastr.infosuccess(`Auto locked personaPersona ${personaName} selected and auto-locked to current chat`, t`Persona Auto LockSelected`);
775777 }
776778 saveMetadataDebounced();
777779 updatePersonaLockIcons();
@@ -788,7 +790,7 @@ function selectCurrentPersona() {
788790 + t`Current Persona: ${power_user.personas[user_avatar]}`
789791 + (hasDifferentChatLock ? '<br />' + t`Chat persona: ${power_user.personas[chat_metadata['persona']]}` : '')
790792 + (hasDifferentDefaultLock ? '<br />' + t`Default persona: ${power_user.personas[power_user.default_persona]}` : '');
791793 toastr.info(message, t`Temporary Persona`, { escapeHtml: false, timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
792794 }
793795 }
794796 }
@@ -865,7 +867,7 @@ async function unlockPersona(type = 'chat') {
865867 delete chat_metadata['persona'];
866868 await saveMetadata();
867869 if (power_user.persona_show_notifications) {
868870 toastr.info(t`User personaPersona ${name1} is now unlocked from this chat. Click the "Lock" again to revert.`, t`Persona unlockedUnlocked`);
869871 }
870872 }
871873 break;
@@ -879,7 +881,7 @@ async function unlockPersona(type = 'chat') {
879881 saveSettingsDebounced();
880882 updatePersonaConnectionsAvatarList();
881883 if (power_user.persona_show_notifications) {
882884 toastr.info(t`User personaPersona ${name1} is now unlocked from character ${name2}. Click the "Lock" again to revert.`, t`Persona unlockedUnlocked`);
883885 }
884886 }
885887 break;
@@ -900,11 +902,7 @@ async function lockPersona(type = 'chat') {
900902 if (!(user_avatar in power_user.personas)) {
901903 console.log(`Creating a new persona ${user_avatar}`);
902904 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- );
908906 }
909907 power_user.personas[user_avatar] = name1;
910908 power_user.persona_descriptions[user_avatar] = {
@@ -1211,7 +1209,7 @@ async function toggleDefaultPersona(avatarId, { quiet: quiet = false } = {}) {
12111209
12121210 power_user.default_persona = avatarId;
12131211 if (power_user.persona_show_notifications) {
12141212 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`);
12151213 }
12161214 }
12171215
@@ -1272,8 +1270,8 @@ async function loadPersonaForCurrentChat() {
12721270 if (connectedPersonas.length === 1) {
12731271 chatPersona = connectedPersonas[0];
12741272 } 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.');
12751274 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`);
12771275 } else {
12781276 chatPersona = await askForPersonaSelection(t`Select Persona`,
12791277 t`Multiple personas are connected to this character.\nSelect a persona to use for this chat.`,
@@ -1307,10 +1305,15 @@ async function loadPersonaForCurrentChat() {
13071305
13081306 // Persona avatar found, select it
13091307 if (chatPersona) {
1310- setUserAvatar(chatPersona);
1308+ const willAutoLock = power_user.persona_auto_lock && user_avatar !== chat_metadata['persona'];
1309+ setUserAvatar(chatPersona, { toastPersonaNameChange: false });
13111310
13121311 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 });
13141317 }
13151318 }
13161319