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)

157046ff46f56af20fc371272f7974f3ed707442

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +8 -13Showing whitespace changes
public/scripts/personas.js+8 -13
@@ -111,6 +111,7 @@ export function setUserAvatar(imgfile, { toastPersonaNameChange = true, navigate
111111 reloadUserAvatar();
112112 updatePersonaUIStates({ navigateToCurrent: navigateToCurrent });
113113 selectCurrentPersona({ toastPersonaNameChange: toastPersonaNameChange });
114+ retriggerFirstMessageOnEmptyChat();
114115 saveSettingsDebounced();
115116 $('.zoomed_avatar[forchar]').remove();
116117}
@@ -465,7 +466,7 @@ export function initPersona(avatarId, personaName, personaDescription) {
465466 * @returns {Promise<boolean>} A promise that resolves to true if the character was converted, false otherwise.
466467 */
467468export async function convertCharacterToPersona(characterId = null) {
468469 if (null === characterId) characterId = Number(this_chid);
469470
470471 const avatarUrl = characters[characterId]?.avatar;
471472 if (!avatarUrl) {
@@ -1243,7 +1244,7 @@ function getPersonaStates(avatarId) {
12431244 /** @type {PersonaConnection[]} */
12441245 const connections = power_user.persona_descriptions[avatarId]?.connections;
12451246 const hasCharLock = !!connections?.some(c =>
12461247 (!selected_group && c.type === 'character' && c.id === characters[Number(this_chid)]?.avatar)
12471248 || (selected_group && c.type === 'group' && c.id === selected_group));
12481249
12491250 return {
@@ -1481,7 +1482,7 @@ async function loadPersonaForCurrentChat({ doRender = false } = {}) {
14811482 * @returns {string[]} - An array of persona keys that are connected to the given character key
14821483 */
14831484export function getConnectedPersonas(characterKey = undefined) {
14841485 characterKey ??= selected_group || characters[Number(this_chid)]?.avatar;
14851486 const connectedPersonas = Object.entries(power_user.persona_descriptions)
14861487 .filter(([_, desc]) => desc.connections?.some(conn => conn.type === 'character' && conn.id === characterKey))
14871488 .map(([key, _]) => key);
@@ -1513,7 +1514,7 @@ export async function showCharConnections() {
15131514 console.log(`Unlocking persona ${personaId} from current character ${name2}`);
15141515 power_user.persona_descriptions[personaId].connections = connections.filter(c => {
15151516 if (menu_type == 'group_edit' && c.type == 'group' && c.id == selected_group) return false;
15161517 else if (c.type == 'character' && c.id == characters[Number(this_chid)]?.avatar) return false;
15171518 return true;
15181519 });
15191520 saveSettingsDebounced();
@@ -1545,8 +1546,8 @@ export async function showCharConnections() {
15451546export function getCurrentConnectionObj() {
15461547 if (selected_group)
15471548 return { type: 'group', id: selected_group };
15481549 if (characters[Number(this_chid)]?.avatar)
15491550 return { type: 'character', id: characters[Number(this_chid)]?.avatar };
15501551 return null;
15511552}
15521553
@@ -1664,7 +1665,7 @@ async function syncUserNameToPersona() {
16641665 * Only works if only the first message is present, and not in group mode.
16651666 */
16661667export function retriggerFirstMessageOnEmptyChat() {
16671668 if (Number(this_chid) >= 0 && !selected_group && chat.length === 1) {
16681669 $('#firstmessage_textarea').trigger('input');
16691670 }
16701671}
@@ -1782,7 +1783,6 @@ function setNameCallback({ mode = 'all' }, name) {
17821783 if (!persona) persona = Object.entries(power_user.personas).find(([_, personaName]) => personaName.toLowerCase() === name.toLowerCase())?.[1];
17831784 if (persona) {
17841785 autoSelectPersona(persona);
1785- retriggerFirstMessageOnEmptyChat();
17861786 return '';
17871787 } else if (mode === 'lookup') {
17881788 toastr.warning(`Persona ${name} not found`);
@@ -1793,7 +1793,6 @@ function setNameCallback({ mode = 'all' }, name) {
17931793 if (['temp', 'all'].includes(mode)) {
17941794 // Otherwise, set just the name
17951795 setUserName(name); //this prevented quickReply usage
1796- retriggerFirstMessageOnEmptyChat();
17971796 }
17981797
17991798 return '';
@@ -1944,9 +1943,6 @@ export async function initPersonas() {
19441943 $(document).on('click', '#user_avatar_block .avatar-container', function () {
19451944 const imgfile = $(this).attr('data-avatar-id');
19461945 setUserAvatar(imgfile);
1947-
1948- // force firstMes {{user}} update on persona switch
1949- retriggerFirstMessageOnEmptyChat();
19501946 });
19511947
19521948 $('#persona_rename_button').on('click', () => renamePersona(user_avatar));
@@ -1979,4 +1975,3 @@ export async function initPersonas() {
19791975 eventSource.on(event_types.CHAT_CHANGED, loadPersonaForCurrentChat);
19801976 switchPersonaGridView();
19811977}
1982-