Enable getPastCharacterChats to work with specific character ids

This commit is contained in:
artisticMink 2023-12-09 14:36:15 +01:00
parent ba3966e148
commit 4692450975
1 changed files with 7 additions and 4 deletions

View File

@ -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
* 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
* in descending order by file name. Returns `undefined` if the fetch request is unsuccessful.
*/
async function getPastCharacterChats() {
if (!characters[this_chid]) return;
export async function getPastCharacterChats(characterId = null) {
characterId = characterId || this_chid;
if (!characters[characterId]) return [];
const response = await fetch('/api/characters/chats', {
method: 'POST',
body: JSON.stringify({ avatar_url: characters[this_chid].avatar }),
body: JSON.stringify({ avatar_url: characters[characterId].avatar }),
headers: getRequestHeaders(),
});
if (!response.ok) {
return;
return [];
}
let data = await response.json();