Add button to show connections for current char

This commit is contained in:
Wolfsblvt
2025-01-25 02:52:41 +01:00
parent 7c12a286c3
commit 608e1c195b
4 changed files with 84 additions and 11 deletions

View File

@ -234,6 +234,8 @@ import {
setPersonaDescription,
initUserAvatar,
updatePersonaConnectionsAvatarList,
getConnectedPersonas,
askForPersonaSelection,
} from './scripts/personas.js';
import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js';
import { hideLoader, showLoader } from './scripts/loader.js';
@ -9985,6 +9987,47 @@ jQuery(async function () {
}
});
$('#char_connections_button').on('click', async () => {
let isRemoving = false;
const connections = getConnectedPersonas();
const message = t`The following personas are connected to the current character.\n\nClick on a persona to select it for the current character.\nShift + Click to unlink the persona from the character.`;
const selectedPersona = await askForPersonaSelection(t`Persona Connections`, message, connections, {
okButton: t`Ok`,
shiftClickHandler: (element, ev) => {
const personaId = $(element).attr('data-pid');
/** @type {import('./scripts/personas.js').PersonaConnection[]} */
const connections = power_user.persona_descriptions[personaId]?.connections;
if (connections) {
console.log(`Unlocking persona ${personaId} from current character ${name2}`);
power_user.persona_descriptions[personaId].connections = connections.filter(c => {
if (menu_type == 'group_edit' && c.type == 'group' && c.id == selected_group) return false;
else if (c.type == 'character' && c.id == characters[this_chid]?.avatar) return false;
return true;
});
saveSettingsDebounced();
updatePersonaConnectionsAvatarList();
if (power_user.persona_show_notifications) {
toastr.info(t`User persona ${power_user.personas[personaId]} is now unlocked from the current character ${name2}.`, t`Persona unlocked`);
}
isRemoving = true;
$('#char_connections_button').trigger('click');
}
},
});
// One of the persona was selected. So load it.
if (!isRemoving && selectedPersona) {
setUserAvatar(selectedPersona);
if (power_user.persona_show_notifications) {
toastr.info(t`Selected persona ${power_user.personas[selectedPersona]} for current chat.`, t`Connected Persona Selected`);
}
}
});
$('#character_cross').click(function () {
is_advanced_char_open = false;
$('#character_popup').transition({