Merge pull request #3778 from SillyTavern/fix/persona-select-rerender-first-message Fix persona select on new chat not rerendering first message (and not replacing `{{user}}` macro)
Signed| @@ -111,6 +111,7 @@ export function setUserAvatar(imgfile, { toastPersonaNameChange = true, navigate | ||
| 111 | 111 | reloadUserAvatar(); |
| 112 | 112 | updatePersonaUIStates({ navigateToCurrent: navigateToCurrent }); |
| 113 | 113 | selectCurrentPersona({ toastPersonaNameChange: toastPersonaNameChange }); |
| 114 | + retriggerFirstMessageOnEmptyChat(); | |
| 114 | 115 | saveSettingsDebounced(); |
| 115 | 116 | $('.zoomed_avatar[forchar]').remove(); |
| 116 | 117 | } |
| @@ -465,7 +466,7 @@ export function initPersona(avatarId, personaName, personaDescription) { | ||
| 465 | 466 | * @returns {Promise<boolean>} A promise that resolves to true if the character was converted, false otherwise. |
| 466 | 467 | */ |
| 467 | 468 | export async function convertCharacterToPersona(characterId = null) { |
| 468 | 469 | if (null === characterId) characterId = Number(this_chid); |
| 469 | 470 | |
| 470 | 471 | const avatarUrl = characters[characterId]?.avatar; |
| 471 | 472 | if (!avatarUrl) { |
| @@ -1243,7 +1244,7 @@ function getPersonaStates(avatarId) { | ||
| 1243 | 1244 | /** @type {PersonaConnection[]} */ |
| 1244 | 1245 | const connections = power_user.persona_descriptions[avatarId]?.connections; |
| 1245 | 1246 | const hasCharLock = !!connections?.some(c => |
| 1246 | 1247 | (!selected_group && c.type === 'character' && c.id === characters[Number(this_chid)]?.avatar) |
| 1247 | 1248 | || (selected_group && c.type === 'group' && c.id === selected_group)); |
| 1248 | 1249 | |
| 1249 | 1250 | return { |
| @@ -1481,7 +1482,7 @@ async function loadPersonaForCurrentChat({ doRender = false } = {}) { | ||
| 1481 | 1482 | * @returns {string[]} - An array of persona keys that are connected to the given character key |
| 1482 | 1483 | */ |
| 1483 | 1484 | export function getConnectedPersonas(characterKey = undefined) { |
| 1484 | 1485 | characterKey ??= selected_group || characters[Number(this_chid)]?.avatar; |
| 1485 | 1486 | const connectedPersonas = Object.entries(power_user.persona_descriptions) |
| 1486 | 1487 | .filter(([_, desc]) => desc.connections?.some(conn => conn.type === 'character' && conn.id === characterKey)) |
| 1487 | 1488 | .map(([key, _]) => key); |
| @@ -1513,7 +1514,7 @@ export async function showCharConnections() { | ||
| 1513 | 1514 | console.log(`Unlocking persona ${personaId} from current character ${name2}`); |
| 1514 | 1515 | power_user.persona_descriptions[personaId].connections = connections.filter(c => { |
| 1515 | 1516 | if (menu_type == 'group_edit' && c.type == 'group' && c.id == selected_group) return false; |
| 1516 | 1517 | else if (c.type == 'character' && c.id == characters[Number(this_chid)]?.avatar) return false; |
| 1517 | 1518 | return true; |
| 1518 | 1519 | }); |
| 1519 | 1520 | saveSettingsDebounced(); |
| @@ -1545,8 +1546,8 @@ export async function showCharConnections() { | ||
| 1545 | 1546 | export function getCurrentConnectionObj() { |
| 1546 | 1547 | if (selected_group) |
| 1547 | 1548 | return { type: 'group', id: selected_group }; |
| 1548 | 1549 | if (characters[Number(this_chid)]?.avatar) |
| 1549 | 1550 | return { type: 'character', id: characters[Number(this_chid)]?.avatar }; |
| 1550 | 1551 | return null; |
| 1551 | 1552 | } |
| 1552 | 1553 | |
| @@ -1664,7 +1665,7 @@ async function syncUserNameToPersona() { | ||
| 1664 | 1665 | * Only works if only the first message is present, and not in group mode. |
| 1665 | 1666 | */ |
| 1666 | 1667 | export function retriggerFirstMessageOnEmptyChat() { |
| 1667 | 1668 | if (Number(this_chid) >= 0 && !selected_group && chat.length === 1) { |
| 1668 | 1669 | $('#firstmessage_textarea').trigger('input'); |
| 1669 | 1670 | } |
| 1670 | 1671 | } |
| @@ -1782,7 +1783,6 @@ function setNameCallback({ mode = 'all' }, name) { | ||
| 1782 | 1783 | if (!persona) persona = Object.entries(power_user.personas).find(([_, personaName]) => personaName.toLowerCase() === name.toLowerCase())?.[1]; |
| 1783 | 1784 | if (persona) { |
| 1784 | 1785 | autoSelectPersona(persona); |
| 1785 | - retriggerFirstMessageOnEmptyChat(); | |
| 1786 | 1786 | return ''; |
| 1787 | 1787 | } else if (mode === 'lookup') { |
| 1788 | 1788 | toastr.warning(`Persona ${name} not found`); |
| @@ -1793,7 +1793,6 @@ function setNameCallback({ mode = 'all' }, name) { | ||
| 1793 | 1793 | if (['temp', 'all'].includes(mode)) { |
| 1794 | 1794 | // Otherwise, set just the name |
| 1795 | 1795 | setUserName(name); //this prevented quickReply usage |
| 1796 | - retriggerFirstMessageOnEmptyChat(); | |
| 1797 | 1796 | } |
| 1798 | 1797 | |
| 1799 | 1798 | return ''; |
| @@ -1944,9 +1943,6 @@ export async function initPersonas() { | ||
| 1944 | 1943 | $(document).on('click', '#user_avatar_block .avatar-container', function () { |
| 1945 | 1944 | const imgfile = $(this).attr('data-avatar-id'); |
| 1946 | 1945 | setUserAvatar(imgfile); |
| 1947 | - | |
| 1948 | - // force firstMes {{user}} update on persona switch | |
| 1949 | - retriggerFirstMessageOnEmptyChat(); | |
| 1950 | 1946 | }); |
| 1951 | 1947 | |
| 1952 | 1948 | $('#persona_rename_button').on('click', () => renamePersona(user_avatar)); |
| @@ -1979,4 +1975,3 @@ export async function initPersonas() { | ||
| 1979 | 1975 | eventSource.on(event_types.CHAT_CHANGED, loadPersonaForCurrentChat); |
| 1980 | 1976 | switchPersonaGridView(); |
| 1981 | 1977 | } |
| 1982 | - | |