bonus: jsdoc and modern popup for rename
| @@ -6271,6 +6271,23 @@ export function setSendButtonState(value) { | ||
| 6271 | 6271 | is_send_press = value; |
| 6272 | 6272 | } |
| 6273 | 6273 | |
| 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 | + | |
| 6274 | 6291 | export async function renameCharacter(name = null, { silent = false, renameChats = null } = {}) { |
| 6275 | 6292 | if (!name && silent) { |
| 6276 | 6293 | toastr.warning(t`No character name provided.`, t`Rename Character`); |
| @@ -6354,10 +6371,15 @@ export async function renameCharacter(name = null, { silent = false, renameChats | ||
| 6354 | 6371 | |
| 6355 | 6372 | // Also rename as a group member |
| 6356 | 6373 | await renameGroupMember(oldAvatar, newAvatar, newValue); |
| 6357 | 6374 | 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; | |
| 6361 | 6383 | |
| 6362 | 6384 | if (renamePastChatsConfirm) { |
| 6363 | 6385 | await renamePastChats(oldAvatar, newAvatar, newValue); |
| @@ -6377,7 +6399,7 @@ export async function renameCharacter(name = null, { silent = false, renameChats | ||
| 6377 | 6399 | } |
| 6378 | 6400 | catch (error) { |
| 6379 | 6401 | // Reloading to prevent data corruption |
| 6380 | 6402 | if (!silent) await callPopupPopup.show.text(t`Rename Character`, t`Something went wrong. The page will be reloaded.`, 'text'); |
| 6381 | 6403 | else toastr.error(t`Something went wrong. The page will be reloaded.`, t`Rename Character`); |
| 6382 | 6404 | |
| 6383 | 6405 | console.log('Renaming character error:', error); |