mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #1498 from artisticMink/bulkedit-delete-optimization
Only refresh character list after all deletions have been processed.
This commit is contained in:
@ -5921,20 +5921,23 @@ export async function getChatsFromFiles(data, isGroupChat) {
|
|||||||
* The function sends a POST request to the server to retrieve all chats for the character. It then
|
* The function sends a POST request to the server to retrieve all chats for the character. It then
|
||||||
* processes the received data, sorts it by the file name, and returns the sorted data.
|
* processes the received data, sorts it by the file name, and returns the sorted data.
|
||||||
*
|
*
|
||||||
|
* @param {null|number} [characterId=null] - When set, the function will use this character id instead of this_chid.
|
||||||
|
*
|
||||||
* @returns {Promise<Array>} - An array containing metadata of all past chats of the character, sorted
|
* @returns {Promise<Array>} - An array containing metadata of all past chats of the character, sorted
|
||||||
* in descending order by file name. Returns `undefined` if the fetch request is unsuccessful.
|
* in descending order by file name. Returns `undefined` if the fetch request is unsuccessful.
|
||||||
*/
|
*/
|
||||||
async function getPastCharacterChats() {
|
export async function getPastCharacterChats(characterId = null) {
|
||||||
if (!characters[this_chid]) return;
|
characterId = characterId ?? this_chid;
|
||||||
|
if (!characters[characterId]) return [];
|
||||||
|
|
||||||
const response = await fetch('/api/characters/chats', {
|
const response = await fetch('/api/characters/chats', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ avatar_url: characters[this_chid].avatar }),
|
body: JSON.stringify({ avatar_url: characters[characterId].avatar }),
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
@ -7652,8 +7655,9 @@ export async function handleDeleteCharacter(popup_type, this_chid, delete_chats)
|
|||||||
*
|
*
|
||||||
* @param {string} name - The name of the character to be deleted.
|
* @param {string} name - The name of the character to be deleted.
|
||||||
* @param {string} avatar - The avatar URL of the character to be deleted.
|
* @param {string} avatar - The avatar URL of the character to be deleted.
|
||||||
|
* @param {boolean} reloadCharacters - Whether the character list should be refreshed after deletion.
|
||||||
*/
|
*/
|
||||||
export async function deleteCharacter(name, avatar) {
|
export async function deleteCharacter(name, avatar, reloadCharacters = true) {
|
||||||
await clearChat();
|
await clearChat();
|
||||||
$('#character_cross').click();
|
$('#character_cross').click();
|
||||||
this_chid = 'invalid-safety-id';
|
this_chid = 'invalid-safety-id';
|
||||||
@ -7664,7 +7668,7 @@ export async function deleteCharacter(name, avatar) {
|
|||||||
$(document.getElementById('rm_button_selected_ch')).children('h2').text('');
|
$(document.getElementById('rm_button_selected_ch')).children('h2').text('');
|
||||||
this_chid = undefined;
|
this_chid = undefined;
|
||||||
delete tag_map[avatar];
|
delete tag_map[avatar];
|
||||||
await getCharacters();
|
if (reloadCharacters) await getCharacters();
|
||||||
select_rm_info('char_delete', name);
|
select_rm_info('char_delete', name);
|
||||||
await printMessages();
|
await printMessages();
|
||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
|
@ -7,9 +7,9 @@ import {
|
|||||||
event_types,
|
event_types,
|
||||||
eventSource,
|
eventSource,
|
||||||
getCharacters,
|
getCharacters,
|
||||||
|
getPastCharacterChats,
|
||||||
getRequestHeaders,
|
getRequestHeaders,
|
||||||
printCharacters,
|
printCharacters,
|
||||||
this_chid,
|
|
||||||
} from '../script.js';
|
} from '../script.js';
|
||||||
|
|
||||||
import { favsToHotswap } from './RossAscends-mods.js';
|
import { favsToHotswap } from './RossAscends-mods.js';
|
||||||
@ -123,27 +123,16 @@ class CharacterContextMenu {
|
|||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
deleteCharacter(character.name, character.avatar).then(() => {
|
return deleteCharacter(character.name, character.avatar, false).then(() => {
|
||||||
if (deleteChats) {
|
eventSource.emit('characterDeleted', { id: characterId, character: characters[characterId] });
|
||||||
fetch('/api/characters/chats', {
|
if (deleteChats) getPastCharacterChats(characterId).then(pastChats => {
|
||||||
method: 'POST',
|
for (const chat of pastChats) {
|
||||||
body: JSON.stringify({ avatar_url: character.avatar }),
|
const name = chat.file_name.replace('.jsonl', '');
|
||||||
headers: getRequestHeaders(),
|
eventSource.emit(event_types.CHAT_DELETED, name);
|
||||||
}).then((response) => {
|
}
|
||||||
let data = response.json();
|
});
|
||||||
data = Object.values(data);
|
|
||||||
const pastChats = data.sort((a, b) => a['file_name'].localeCompare(b['file_name'])).reverse();
|
|
||||||
|
|
||||||
for (const chat of pastChats) {
|
|
||||||
const name = chat.file_name.replace('.jsonl', '');
|
|
||||||
eventSource.emit(event_types.CHAT_DELETED, name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
eventSource.emit('characterDeleted', { id: this_chid, character: characters[this_chid] });
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -626,12 +615,11 @@ class BulkEditOverlay {
|
|||||||
|
|
||||||
showLoader();
|
showLoader();
|
||||||
toastr.info('We\'re deleting your characters, please wait...', 'Working on it');
|
toastr.info('We\'re deleting your characters, please wait...', 'Working on it');
|
||||||
Promise.all(this.selectedCharacters.map(async characterId => CharacterContextMenu.delete(characterId, deleteChats)))
|
Promise.allSettled(this.selectedCharacters.map(async characterId => CharacterContextMenu.delete(characterId, deleteChats)))
|
||||||
.then(() => getCharacters())
|
.then(() => getCharacters())
|
||||||
.then(() => this.browseState())
|
.then(() => this.browseState())
|
||||||
.finally(() => hideLoader());
|
.finally(() => hideLoader());
|
||||||
},
|
});
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user