Navigate to current persona on switching chats

0274d800f992323fa8a7084117d41855ffb49a0f

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

1 files changed, +15 -5Showing whitespace changes
public/scripts/personas.js+15 -5
@@ -68,6 +68,8 @@ export let user_avatar = '';
68/** @type {FilterHelper} Filter helper for the persona list */68/** @type {FilterHelper} Filter helper for the persona list */
69export const personasFilter = new FilterHelper(debounce(getUserAvatars, debounce_timeout.quick));69export const personasFilter = new FilterHelper(debounce(getUserAvatars, debounce_timeout.quick));
7070
71/** @type {function(string): void} */
72let navigateToAvatar = () => { };
7173
72/**74/**
73 * Checks if the Persona Management panel is currently open75 * Checks if the Persona Management panel is currently open
@@ -276,14 +278,16 @@ export async function getUserAvatars(doRender = true, openPageAt = '') {
276 },278 },
277 });279 });
278280
279 if (openPageAt) {281 navigateToAvatar = (avatarId) => {
280 const avatarIndex = entities.indexOf(openPageAt);282 const avatarIndex = entities.indexOf(avatarId);
281 const page = Math.floor(avatarIndex / perPage) + 1;283 const page = Math.floor(avatarIndex / perPage) + 1;
282284
283 if (avatarIndex !== -1) {285 if (avatarIndex !== -1) {
284 $('#persona_pagination_container').pagination('go', page);286 $('#persona_pagination_container').pagination('go', page);
285 }287 }
286 }288 };
289
290 openPageAt && navigateToAvatar(openPageAt);
287291
288 return allEntities;292 return allEntities;
289 }293 }
@@ -1255,9 +1259,15 @@ function getPersonaStates(avatarId) {
1255 * and character lock, as well as updating icons and labels in the persona management panel to reflect1259 * and character lock, as well as updating icons and labels in the persona management panel to reflect
1256 * the current state of the user's persona.1260 * the current state of the user's persona.
1257 * Additionally, it manages the display of temporary persona lock information.1261 * Additionally, it manages the display of temporary persona lock information.
1262 * @param {Object} [options={}] - Optional settings
1263 * @param {boolean} [options.navigateToCurrent=false] - Whether to navigate to the current persona in the persona list
1258 */1264 */
12591265
1260function updatePersonaUIStates() {1266function updatePersonaUIStates({ navigateToCurrent = false } = {}) {
1267 if (navigateToCurrent) {
1268 navigateToAvatar(user_avatar);
1269 }
1270
1261 // Update the persona list1271 // Update the persona list
1262 $('#user_avatar_block .avatar-container').each(function () {1272 $('#user_avatar_block .avatar-container').each(function () {
1263 const avatarId = $(this).attr('data-avatar-id');1273 const avatarId = $(this).attr('data-avatar-id');
@@ -1450,7 +1460,7 @@ async function loadPersonaForCurrentChat({ doRender = false } = {}) {
1450 }1460 }
1451 }1461 }
14521462
1453 updatePersonaUIStates();1463 updatePersonaUIStates({ navigateToCurrent: true });
14541464
1455 return !!chatPersona;1465 return !!chatPersona;
1456}1466}