Merge pull request #4178 from imesha10/staging Make back to parent chat button faster (PR for #4177)

f78be0897eaba620a18045186e30a972305c58ce

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +26 -7Showing whitespace changes
public/scripts/bookmarks.js+26 -7
@@ -14,7 +14,6 @@ import {
1414} from '../script.js';
1515import { humanizedDateTime } from './RossAscends-mods.js';
1616import {
17- getGroupPastChats,
1817 group_activation_strategy,
1918 groups,
2019 openGroupById,
@@ -40,22 +39,42 @@ import {
4039
4140const bookmarkNameToken = 'Checkpoint #';
4241
42+/**
43+ * Gets the names of existing chats for the current character or group.
44+ * @returns {Promise<string[]>} - Returns a promise that resolves to an array of existing chat names.
45+ */
4346async function getExistingChatNames() {
4447 if (selected_group) {
4548 const datagroup = await getGroupPastChatsgroups.find(x => x.id == selected_group);
46- return data.map(x => x.file_name);
49+ if (group && Array.isArray(group.chats)) {
47- } else {
50+ return [...group.chats];
51+ }
52+
53+ return [];
54+ }
55+
56+ if (this_chid === undefined) {
57+ return [];
58+ }
59+
60+ const character = characters[this_chid];
61+ if (!character) {
62+ return [];
63+ }
64+
4865 const response = await fetch('/api/characters/chats', {
4966 method: 'POST',
5067 headers: getRequestHeaders(),
5168 body: JSON.stringify({ avatar_url: characters[this_chid]character.avatar, simple: true }),
5269 });
5370
5471 if (response.ok) {
5572 const data = await response.json();
5673 return const chats = Object.values(data).map(x => x.file_name.replace('.jsonl', ''));
57- }
74+ return [...chats];
5875 }
76+
77+ return [];
5978}
6079
6180async function getBookmarkName({ isReplace = false, forceName = null } = {}) {