Add RENAMED_PAST_CHAT event

4e1cb1eba40bacaead6ede5ba6da265157928c60

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +8 -5Showing whitespace changes
public/script.js+8 -5
@@ -500,6 +500,7 @@ export const event_types = {
500 CHARACTER_DELETED: 'characterDeleted',500 CHARACTER_DELETED: 'characterDeleted',
501 CHARACTER_DUPLICATED: 'character_duplicated',501 CHARACTER_DUPLICATED: 'character_duplicated',
502 CHARACTER_RENAMED: 'character_renamed',502 CHARACTER_RENAMED: 'character_renamed',
503 RENAMED_PAST_CHAT: 'renamed_past_chat',
503 /** @deprecated The event is aliased to STREAM_TOKEN_RECEIVED. */504 /** @deprecated The event is aliased to STREAM_TOKEN_RECEIVED. */
504 SMOOTH_STREAM_TOKEN_RECEIVED: 'stream_token_received',505 SMOOTH_STREAM_TOKEN_RECEIVED: 'stream_token_received',
505 STREAM_TOKEN_RECEIVED: 'stream_token_received',506 STREAM_TOKEN_RECEIVED: 'stream_token_received',
@@ -6359,7 +6360,7 @@ export async function renameCharacter(name = null, { silent = false, renameChats
6359 <i><b>Sprites folder (if any) should be renamed manually.</b></i>`, 'confirm');6360 <i><b>Sprites folder (if any) should be renamed manually.</b></i>`, 'confirm');
63606361
6361 if (renamePastChatsConfirm) {6362 if (renamePastChatsConfirm) {
6362 await renamePastChats(newAvatar, newValue);6363 await renamePastChats(oldAvatar, newAvatar, newValue);
6363 await reloadCurrentChat();6364 await reloadCurrentChat();
6364 toastr.success(t`Character renamed and past chats updated!`, t`Rename Character`);6365 toastr.success(t`Character renamed and past chats updated!`, t`Rename Character`);
6365 } else {6366 } else {
@@ -6387,7 +6388,7 @@ export async function renameCharacter(name = null, { silent = false, renameChats
6387 return true;6388 return true;
6388}6389}
63896390
6390async function renamePastChats(newAvatar, newValue) {6391async function renamePastChats(oldAvatar, newAvatar, newName) {
6391 const pastChats = await getPastCharacterChats();6392 const pastChats = await getPastCharacterChats();
63926393
6393 for (const { file_name } of pastChats) {6394 for (const { file_name } of pastChats) {
@@ -6397,7 +6398,7 @@ async function renamePastChats(newAvatar, newValue) {
6397 method: 'POST',6398 method: 'POST',
6398 headers: getRequestHeaders(),6399 headers: getRequestHeaders(),
6399 body: JSON.stringify({6400 body: JSON.stringify({
6400 ch_name: newValue,6401 ch_name: newName,
6401 file_name: fileNameWithoutExtension,6402 file_name: fileNameWithoutExtension,
6402 avatar_url: newAvatar,6403 avatar_url: newAvatar,
6403 }),6404 }),
@@ -6413,15 +6414,17 @@ async function renamePastChats(newAvatar, newValue) {
6413 }6414 }
64146415
6415 if (message.name !== undefined) {6416 if (message.name !== undefined) {
6416 message.name = newValue;6417 message.name = newName;
6417 }6418 }
6418 }6419 }
64196420
6421 await eventSource.emit(event_types.RENAMED_PAST_CHAT, currentChat, oldAvatar, newAvatar);
6422
6420 const saveChatResponse = await fetch('/api/chats/save', {6423 const saveChatResponse = await fetch('/api/chats/save', {
6421 method: 'POST',6424 method: 'POST',
6422 headers: getRequestHeaders(),6425 headers: getRequestHeaders(),
6423 body: JSON.stringify({6426 body: JSON.stringify({
6424 ch_name: newValue,6427 ch_name: newName,
6425 file_name: fileNameWithoutExtension,6428 file_name: fileNameWithoutExtension,
6426 chat: currentChat,6429 chat: currentChat,
6427 avatar_url: newAvatar,6430 avatar_url: newAvatar,