From 46924509753b9b4c2f2ce61f41fd05e00a05c830 Mon Sep 17 00:00:00 2001 From: artisticMink Date: Sat, 9 Dec 2023 14:36:15 +0100 Subject: [PATCH] Enable getPastCharacterChats to work with specific character ids --- public/script.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/public/script.js b/public/script.js index 082e44c39..a89a9ce46 100644 --- a/public/script.js +++ b/public/script.js @@ -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} - 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();