Refactor: move showCharConnections
| @@ -236,9 +236,6 @@ import { | |||
| 236 | setPersonaDescription, | 236 | setPersonaDescription, |
| 237 | initUserAvatar, | 237 | initUserAvatar, |
| 238 | updatePersonaConnectionsAvatarList, | 238 | updatePersonaConnectionsAvatarList, |
| 239 | getConnectedPersonas, | ||
| 240 | askForPersonaSelection, | ||
| 241 | getCurrentConnectionObj, | ||
| 242 | isPersonaPanelOpen, | 239 | isPersonaPanelOpen, |
| 243 | } from './scripts/personas.js'; | 240 | } from './scripts/personas.js'; |
| 244 | import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js'; | 241 | import { getBackgrounds, initBackgrounds, loadBackgroundSettings, background_settings } from './scripts/backgrounds.js'; |
| @@ -10130,49 +10127,6 @@ jQuery(async function () { | |||
| 10130 | } | 10127 | } |
| 10131 | }); | 10128 | }); |
| 10132 | 10129 | ||
| 10133 | $('#char_connections_button').on('click', async () => { | ||
| 10134 | let isRemoving = false; | ||
| 10135 | |||
| 10136 | const connections = getConnectedPersonas(); | ||
| 10137 | 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.`; | ||
| 10138 | const selectedPersona = await askForPersonaSelection(t`Persona Connections`, message, connections, { | ||
| 10139 | okButton: t`Ok`, | ||
| 10140 | highlightPersonas: true, | ||
| 10141 | targetedChar: getCurrentConnectionObj(), | ||
| 10142 | shiftClickHandler: (element, ev) => { | ||
| 10143 | |||
| 10144 | const personaId = $(element).attr('data-pid'); | ||
| 10145 | |||
| 10146 | /** @type {import('./scripts/personas.js').PersonaConnection[]} */ | ||
| 10147 | const connections = power_user.persona_descriptions[personaId]?.connections; | ||
| 10148 | if (connections) { | ||
| 10149 | console.log(`Unlocking persona ${personaId} from current character ${name2}`); | ||
| 10150 | power_user.persona_descriptions[personaId].connections = connections.filter(c => { | ||
| 10151 | if (menu_type == 'group_edit' && c.type == 'group' && c.id == selected_group) return false; | ||
| 10152 | else if (c.type == 'character' && c.id == characters[this_chid]?.avatar) return false; | ||
| 10153 | return true; | ||
| 10154 | }); | ||
| 10155 | saveSettingsDebounced(); | ||
| 10156 | updatePersonaConnectionsAvatarList(); | ||
| 10157 | if (power_user.persona_show_notifications) { | ||
| 10158 | toastr.info(t`User persona ${power_user.personas[personaId]} is now unlocked from the current character ${name2}.`, t`Persona unlocked`); | ||
| 10159 | } | ||
| 10160 | |||
| 10161 | isRemoving = true; | ||
| 10162 | $('#char_connections_button').trigger('click'); | ||
| 10163 | } | ||
| 10164 | }, | ||
| 10165 | }); | ||
| 10166 | |||
| 10167 | // One of the persona was selected. So load it. | ||
| 10168 | if (!isRemoving && selectedPersona) { | ||
| 10169 | setUserAvatar(selectedPersona, { toastPersonaNameChange: false }); | ||
| 10170 | if (power_user.persona_show_notifications) { | ||
| 10171 | toastr.success(t`Selected persona ${power_user.personas[selectedPersona]} for current chat.`, t`Connected Persona Selected`); | ||
| 10172 | } | ||
| 10173 | } | ||
| 10174 | }); | ||
| 10175 | |||
| 10176 | $('#character_cross').click(function () { | 10130 | $('#character_cross').click(function () { |
| 10177 | is_advanced_char_open = false; | 10131 | is_advanced_char_open = false; |
| 10178 | $('#character_popup').transition({ | 10132 | $('#character_popup').transition({ |
| @@ -10,6 +10,7 @@ import { | |||
| 10 | getRequestHeaders, | 10 | getRequestHeaders, |
| 11 | getThumbnailUrl, | 11 | getThumbnailUrl, |
| 12 | groupToEntity, | 12 | groupToEntity, |
| 13 | menu_type, | ||
| 13 | name1, | 14 | name1, |
| 14 | name2, | 15 | name2, |
| 15 | reloadCurrentChat, | 16 | reloadCurrentChat, |
| @@ -1363,6 +1364,55 @@ export function getConnectedPersonas(characterKey = undefined) { | |||
| 1363 | return connectedPersonas; | 1364 | return connectedPersonas; |
| 1364 | } | 1365 | } |
| 1365 | 1366 | ||
| 1367 | |||
| 1368 | /** | ||
| 1369 | * Shows a popup with all personas connected to the currently selected character or group. | ||
| 1370 | * In the popup, the user can select a persona to load for the current character or group, or shift-click to remove the connection. | ||
| 1371 | * @return {Promise<void>} | ||
| 1372 | */ | ||
| 1373 | export async function showCharConnections() { | ||
| 1374 | let isRemoving = false; | ||
| 1375 | |||
| 1376 | const connections = getConnectedPersonas(); | ||
| 1377 | 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.`; | ||
| 1378 | const selectedPersona = await askForPersonaSelection(t`Persona Connections`, message, connections, { | ||
| 1379 | okButton: t`Ok`, | ||
| 1380 | highlightPersonas: true, | ||
| 1381 | targetedChar: getCurrentConnectionObj(), | ||
| 1382 | shiftClickHandler: (element, ev) => { | ||
| 1383 | |||
| 1384 | const personaId = $(element).attr('data-pid'); | ||
| 1385 | |||
| 1386 | /** @type {PersonaConnection[]} */ | ||
| 1387 | const connections = power_user.persona_descriptions[personaId]?.connections; | ||
| 1388 | if (connections) { | ||
| 1389 | console.log(`Unlocking persona ${personaId} from current character ${name2}`); | ||
| 1390 | power_user.persona_descriptions[personaId].connections = connections.filter(c => { | ||
| 1391 | if (menu_type == 'group_edit' && c.type == 'group' && c.id == selected_group) return false; | ||
| 1392 | else if (c.type == 'character' && c.id == characters[this_chid]?.avatar) return false; | ||
| 1393 | return true; | ||
| 1394 | }); | ||
| 1395 | saveSettingsDebounced(); | ||
| 1396 | updatePersonaConnectionsAvatarList(); | ||
| 1397 | if (power_user.persona_show_notifications) { | ||
| 1398 | toastr.info(t`User persona ${power_user.personas[personaId]} is now unlocked from the current character ${name2}.`, t`Persona unlocked`); | ||
| 1399 | } | ||
| 1400 | |||
| 1401 | isRemoving = true; | ||
| 1402 | $('#char_connections_button').trigger('click'); | ||
| 1403 | } | ||
| 1404 | }, | ||
| 1405 | }); | ||
| 1406 | |||
| 1407 | // One of the persona was selected. So load it. | ||
| 1408 | if (!isRemoving && selectedPersona) { | ||
| 1409 | setUserAvatar(selectedPersona, { toastPersonaNameChange: false }); | ||
| 1410 | if (power_user.persona_show_notifications) { | ||
| 1411 | toastr.success(t`Selected persona ${power_user.personas[selectedPersona]} for current chat.`, t`Connected Persona Selected`); | ||
| 1412 | } | ||
| 1413 | } | ||
| 1414 | } | ||
| 1415 | |||
| 1366 | /** | 1416 | /** |
| 1367 | * Retrieves the current connection object based on whether the current chat is with a char or a group. | 1417 | * Retrieves the current connection object based on whether the current chat is with a char or a group. |
| 1368 | * | 1418 | * |
| @@ -1542,6 +1592,7 @@ function migrateNonPersonaUser() { | |||
| 1542 | saveSettingsDebounced(); | 1592 | saveSettingsDebounced(); |
| 1543 | } | 1593 | } |
| 1544 | 1594 | ||
| 1595 | |||
| 1545 | export function initPersonas() { | 1596 | export function initPersonas() { |
| 1546 | migrateNonPersonaUser(); | 1597 | migrateNonPersonaUser(); |
| 1547 | $('#persona_delete_button').on('click', deleteUserAvatar); | 1598 | $('#persona_delete_button').on('click', deleteUserAvatar); |
| @@ -1609,6 +1660,8 @@ export function initPersonas() { | |||
| 1609 | $('#avatar_upload_file').trigger('click'); | 1660 | $('#avatar_upload_file').trigger('click'); |
| 1610 | }); | 1661 | }); |
| 1611 | 1662 | ||
| 1663 | $('#char_connections_button').on('click', showCharConnections); | ||
| 1664 | |||
| 1612 | eventSource.on('charManagementDropdown', (target) => { | 1665 | eventSource.on('charManagementDropdown', (target) => { |
| 1613 | if (target === 'convert_to_persona') { | 1666 | if (target === 'convert_to_persona') { |
| 1614 | convertCharacterToPersona(); | 1667 | convertCharacterToPersona(); |
| @@ -1617,3 +1670,4 @@ export function initPersonas() { | |||
| 1617 | eventSource.on(event_types.CHAT_CHANGED, loadPersonaForCurrentChat); | 1670 | eventSource.on(event_types.CHAT_CHANGED, loadPersonaForCurrentChat); |
| 1618 | switchPersonaGridView(); | 1671 | switchPersonaGridView(); |
| 1619 | } | 1672 | } |
| 1673 | |||