mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
bonus: jsdoc and modern popup for rename
This commit is contained in:
@ -6271,6 +6271,23 @@ export function setSendButtonState(value) {
|
|||||||
is_send_press = value;
|
is_send_press = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renames the currently selected character, updating relevant references and optionally renaming past chats.
|
||||||
|
*
|
||||||
|
* If no name is provided, a popup prompts for a new name. If the new name matches the current name,
|
||||||
|
* the renaming process is aborted. The function sends a request to the server to rename the character
|
||||||
|
* and handles updates to other related fields such as tags, lore, and author notes.
|
||||||
|
*
|
||||||
|
* If the renaming is successful, the character list is reloaded and the renamed character is selected.
|
||||||
|
* Optionally, past chats can be renamed to reflect the new character name.
|
||||||
|
*
|
||||||
|
* @param {string?} [name=null] - The new name for the character. If not provided, a popup will prompt for it.
|
||||||
|
* @param {object} [options] - Additional options.
|
||||||
|
* @param {boolean} [options.silent=false] - If true, suppresses popups and warnings.
|
||||||
|
* @param {boolean?} [options.renameChats=null] - If true, renames past chats to reflect the new character name.
|
||||||
|
* @returns {Promise<boolean>} - Returns true if the character was successfully renamed, false otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
export async function renameCharacter(name = null, { silent = false, renameChats = null } = {}) {
|
export async function renameCharacter(name = null, { silent = false, renameChats = null } = {}) {
|
||||||
if (!name && silent) {
|
if (!name && silent) {
|
||||||
toastr.warning(t`No character name provided.`, t`Rename Character`);
|
toastr.warning(t`No character name provided.`, t`Rename Character`);
|
||||||
@ -6354,10 +6371,15 @@ export async function renameCharacter(name = null, { silent = false, renameChats
|
|||||||
|
|
||||||
// Also rename as a group member
|
// Also rename as a group member
|
||||||
await renameGroupMember(oldAvatar, newAvatar, newValue);
|
await renameGroupMember(oldAvatar, newAvatar, newValue);
|
||||||
const renamePastChatsConfirm = renameChats !== null ? renameChats
|
const renamePastChatsConfirm = renameChats !== null
|
||||||
: silent ? false : await callPopup(`<h3>Character renamed!</h3>
|
? renameChats
|
||||||
<p>Past chats will still contain the old character name. Would you like to update the character name in previous chats as well?</p>
|
: silent
|
||||||
<i><b>Sprites folder (if any) should be renamed manually.</b></i>`, 'confirm');
|
? false
|
||||||
|
: await Popup.show.confirm(
|
||||||
|
t`Character renamed!`,
|
||||||
|
`<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>
|
||||||
|
<i><b>${t`Sprites folder (if any) should be renamed manually.`}</b></i>`,
|
||||||
|
) == POPUP_RESULT.AFFIRMATIVE;
|
||||||
|
|
||||||
if (renamePastChatsConfirm) {
|
if (renamePastChatsConfirm) {
|
||||||
await renamePastChats(oldAvatar, newAvatar, newValue);
|
await renamePastChats(oldAvatar, newAvatar, newValue);
|
||||||
@ -6377,7 +6399,7 @@ export async function renameCharacter(name = null, { silent = false, renameChats
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
// Reloading to prevent data corruption
|
// Reloading to prevent data corruption
|
||||||
if (!silent) await callPopup(t`Something went wrong. The page will be reloaded.`, 'text');
|
if (!silent) await Popup.show.text(t`Rename Character`, t`Something went wrong. The page will be reloaded.`);
|
||||||
else toastr.error(t`Something went wrong. The page will be reloaded.`, t`Rename Character`);
|
else toastr.error(t`Something went wrong. The page will be reloaded.`, t`Rename Character`);
|
||||||
|
|
||||||
console.log('Renaming character error:', error);
|
console.log('Renaming character error:', error);
|
||||||
|
Reference in New Issue
Block a user