bonus: jsdoc and modern popup for rename

22d551be3a93a50f7608f499c82c02a9b67b2cb2

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +27 -5Ignore whitespace
public/script.js+27 -5
@@ -6271,6 +6271,23 @@ export function setSendButtonState(value) {
6271 is_send_press = value;6271 is_send_press = value;
6272}6272}
62736273
6274/**
6275 * Renames the currently selected character, updating relevant references and optionally renaming past chats.
6276 *
6277 * If no name is provided, a popup prompts for a new name. If the new name matches the current name,
6278 * the renaming process is aborted. The function sends a request to the server to rename the character
6279 * and handles updates to other related fields such as tags, lore, and author notes.
6280 *
6281 * If the renaming is successful, the character list is reloaded and the renamed character is selected.
6282 * Optionally, past chats can be renamed to reflect the new character name.
6283 *
6284 * @param {string?} [name=null] - The new name for the character. If not provided, a popup will prompt for it.
6285 * @param {object} [options] - Additional options.
6286 * @param {boolean} [options.silent=false] - If true, suppresses popups and warnings.
6287 * @param {boolean?} [options.renameChats=null] - If true, renames past chats to reflect the new character name.
6288 * @returns {Promise<boolean>} - Returns true if the character was successfully renamed, false otherwise.
6289 */
6290
6274export async function renameCharacter(name = null, { silent = false, renameChats = null } = {}) {6291export async function renameCharacter(name = null, { silent = false, renameChats = null } = {}) {
6275 if (!name && silent) {6292 if (!name && silent) {
6276 toastr.warning(t`No character name provided.`, t`Rename Character`);6293 toastr.warning(t`No character name provided.`, t`Rename Character`);
@@ -6354,10 +6371,15 @@ export async function renameCharacter(name = null, { silent = false, renameChats
63546371
6355 // Also rename as a group member6372 // Also rename as a group member
6356 await renameGroupMember(oldAvatar, newAvatar, newValue);6373 await renameGroupMember(oldAvatar, newAvatar, newValue);
6357 const renamePastChatsConfirm = renameChats !== null ? renameChats6374 const renamePastChatsConfirm = renameChats !== null
6358 : silent ? false : await callPopup(`<h3>Character renamed!</h3>6375 ? renameChats
6359 <p>Past chats will still contain the old character name. Would you like to update the character name in previous chats as well?</p>6376 : silent
6360 <i><b>Sprites folder (if any) should be renamed manually.</b></i>`, 'confirm');6377 ? false
6378 : await Popup.show.confirm(
6379 t`Character renamed!`,
6380 `<p>${t`Past chats will still contain the old character name. Would you like to update the character name in previous chats as well?`}</p>
6381 <i><b>${t`Sprites folder (if any) should be renamed manually.`}</b></i>`,
6382 ) == POPUP_RESULT.AFFIRMATIVE;
63616383
6362 if (renamePastChatsConfirm) {6384 if (renamePastChatsConfirm) {
6363 await renamePastChats(oldAvatar, newAvatar, newValue);6385 await renamePastChats(oldAvatar, newAvatar, newValue);
@@ -6377,7 +6399,7 @@ export async function renameCharacter(name = null, { silent = false, renameChats
6377 }6399 }
6378 catch (error) {6400 catch (error) {
6379 // Reloading to prevent data corruption6401 // Reloading to prevent data corruption
6380 if (!silent) await callPopup(t`Something went wrong. The page will be reloaded.`, 'text');6402 if (!silent) await Popup.show.text(t`Rename Character`, t`Something went wrong. The page will be reloaded.`);
6381 else toastr.error(t`Something went wrong. The page will be reloaded.`, t`Rename Character`);6403 else toastr.error(t`Something went wrong. The page will be reloaded.`, t`Rename Character`);
63826404
6383 console.log('Renaming character error:', error);6405 console.log('Renaming character error:', error);