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) {
62716271 is_send_press = value;
62726272}
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+
62746291export async function renameCharacter(name = null, { silent = false, renameChats = null } = {}) {
62756292 if (!name && silent) {
62766293 toastr.warning(t`No character name provided.`, t`Rename Character`);
@@ -6354,10 +6371,15 @@ export async function renameCharacter(name = null, { silent = false, renameChats
63546371
63556372 // Also rename as a group member
63566373 await renameGroupMember(oldAvatar, newAvatar, newValue);
63576374 const renamePastChatsConfirm = renameChats !== null ? renameChats
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
63626384 if (renamePastChatsConfirm) {
63636385 await renamePastChats(oldAvatar, newAvatar, newValue);
@@ -6377,7 +6399,7 @@ export async function renameCharacter(name = null, { silent = false, renameChats
63776399 }
63786400 catch (error) {
63796401 // Reloading to prevent data corruption
63806402 if (!silent) await callPopupPopup.show.text(t`Rename Character`, t`Something went wrong. The page will be reloaded.`, 'text');
63816403 else toastr.error(t`Something went wrong. The page will be reloaded.`, t`Rename Character`);
63826404
63836405 console.log('Renaming character error:', error);