Cast this_chid to number in personas.js Ensure numeric type for character ID comparisons Explicitly converts this_chid to Number in multiple functions to prevent type mismatch issues when checking character connections and persona states
| @@ -465,7 +465,7 @@ export function initPersona(avatarId, personaName, personaDescription) { | |||
| 465 | * @returns {Promise<boolean>} A promise that resolves to true if the character was converted, false otherwise. | 465 | * @returns {Promise<boolean>} A promise that resolves to true if the character was converted, false otherwise. |
| 466 | */ | 466 | */ |
| 467 | export async function convertCharacterToPersona(characterId = null) { | 467 | export async function convertCharacterToPersona(characterId = null) { |
| 468 | if (null === characterId) characterId = this_chid; | 468 | if (null === characterId) characterId = Number(this_chid); |
| 469 | 469 | ||
| 470 | const avatarUrl = characters[characterId]?.avatar; | 470 | const avatarUrl = characters[characterId]?.avatar; |
| 471 | if (!avatarUrl) { | 471 | if (!avatarUrl) { |
| @@ -1243,7 +1243,7 @@ function getPersonaStates(avatarId) { | |||
| 1243 | /** @type {PersonaConnection[]} */ | 1243 | /** @type {PersonaConnection[]} */ |
| 1244 | const connections = power_user.persona_descriptions[avatarId]?.connections; | 1244 | const connections = power_user.persona_descriptions[avatarId]?.connections; |
| 1245 | const hasCharLock = !!connections?.some(c => | 1245 | const hasCharLock = !!connections?.some(c => |
| 1246 | (!selected_group && c.type === 'character' && c.id === characters[this_chid]?.avatar) | 1246 | (!selected_group && c.type === 'character' && c.id === characters[Number(this_chid)]?.avatar) |
| 1247 | || (selected_group && c.type === 'group' && c.id === selected_group)); | 1247 | || (selected_group && c.type === 'group' && c.id === selected_group)); |
| 1248 | 1248 | ||
| 1249 | return { | 1249 | return { |
| @@ -1481,7 +1481,7 @@ async function loadPersonaForCurrentChat({ doRender = false } = {}) { | |||
| 1481 | * @returns {string[]} - An array of persona keys that are connected to the given character key | 1481 | * @returns {string[]} - An array of persona keys that are connected to the given character key |
| 1482 | */ | 1482 | */ |
| 1483 | export function getConnectedPersonas(characterKey = undefined) { | 1483 | export function getConnectedPersonas(characterKey = undefined) { |
| 1484 | characterKey ??= selected_group || characters[this_chid]?.avatar; | 1484 | characterKey ??= selected_group || characters[Number(this_chid)]?.avatar; |
| 1485 | const connectedPersonas = Object.entries(power_user.persona_descriptions) | 1485 | const connectedPersonas = Object.entries(power_user.persona_descriptions) |
| 1486 | .filter(([_, desc]) => desc.connections?.some(conn => conn.type === 'character' && conn.id === characterKey)) | 1486 | .filter(([_, desc]) => desc.connections?.some(conn => conn.type === 'character' && conn.id === characterKey)) |
| 1487 | .map(([key, _]) => key); | 1487 | .map(([key, _]) => key); |
| @@ -1513,7 +1513,7 @@ export async function showCharConnections() { | |||
| 1513 | console.log(`Unlocking persona ${personaId} from current character ${name2}`); | 1513 | console.log(`Unlocking persona ${personaId} from current character ${name2}`); |
| 1514 | power_user.persona_descriptions[personaId].connections = connections.filter(c => { | 1514 | power_user.persona_descriptions[personaId].connections = connections.filter(c => { |
| 1515 | if (menu_type == 'group_edit' && c.type == 'group' && c.id == selected_group) return false; | 1515 | if (menu_type == 'group_edit' && c.type == 'group' && c.id == selected_group) return false; |
| 1516 | else if (c.type == 'character' && c.id == characters[this_chid]?.avatar) return false; | 1516 | else if (c.type == 'character' && c.id == characters[Number(this_chid)]?.avatar) return false; |
| 1517 | return true; | 1517 | return true; |
| 1518 | }); | 1518 | }); |
| 1519 | saveSettingsDebounced(); | 1519 | saveSettingsDebounced(); |
| @@ -1545,8 +1545,8 @@ export async function showCharConnections() { | |||
| 1545 | export function getCurrentConnectionObj() { | 1545 | export function getCurrentConnectionObj() { |
| 1546 | if (selected_group) | 1546 | if (selected_group) |
| 1547 | return { type: 'group', id: selected_group }; | 1547 | return { type: 'group', id: selected_group }; |
| 1548 | if (characters[this_chid]?.avatar) | 1548 | if (characters[Number(this_chid)]?.avatar) |
| 1549 | return { type: 'character', id: characters[this_chid]?.avatar }; | 1549 | return { type: 'character', id: characters[Number(this_chid)]?.avatar }; |
| 1550 | return null; | 1550 | return null; |
| 1551 | } | 1551 | } |
| 1552 | 1552 | ||
| @@ -1664,7 +1664,7 @@ async function syncUserNameToPersona() { | |||
| 1664 | * Only works if only the first message is present, and not in group mode. | 1664 | * Only works if only the first message is present, and not in group mode. |
| 1665 | */ | 1665 | */ |
| 1666 | export function retriggerFirstMessageOnEmptyChat() { | 1666 | export function retriggerFirstMessageOnEmptyChat() { |
| 1667 | if (this_chid >= 0 && !selected_group && chat.length === 1) { | 1667 | if (Number(this_chid) >= 0 && !selected_group && chat.length === 1) { |
| 1668 | $('#firstmessage_textarea').trigger('input'); | 1668 | $('#firstmessage_textarea').trigger('input'); |
| 1669 | } | 1669 | } |
| 1670 | } | 1670 | } |
| @@ -1979,4 +1979,3 @@ export async function initPersonas() { | |||
| 1979 | eventSource.on(event_types.CHAT_CHANGED, loadPersonaForCurrentChat); | 1979 | eventSource.on(event_types.CHAT_CHANGED, loadPersonaForCurrentChat); |
| 1980 | switchPersonaGridView(); | 1980 | switchPersonaGridView(); |
| 1981 | } | 1981 | } |
| 1982 | |||