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, +32 -13Ignore whitespace
public/scripts/bookmarks.js+32 -13
@@ -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];
48- const response = await fetch('/api/characters/chats', {
49- method: 'POST',
50- headers: getRequestHeaders(),
51- body: JSON.stringify({ avatar_url: characters[this_chid].avatar }),
52- });
53-
54- if (response.ok) {
55- const data = await response.json();
56- return Object.values(data).map(x => x.file_name.replace('.jsonl', ''));
5751 }
52+
53+ return [];
5854 }
55+
56+ if (this_chid === undefined) {
57+ return [];
58+ }
59+
60+ const character = characters[this_chid];
61+ if (!character) {
62+ return [];
63+ }
64+
65+ const response = await fetch('/api/characters/chats', {
66+ method: 'POST',
67+ headers: getRequestHeaders(),
68+ body: JSON.stringify({ avatar_url: character.avatar, simple: true }),
69+ });
70+
71+ if (response.ok) {
72+ const data = await response.json();
73+ const chats = Object.values(data).map(x => x.file_name.replace('.jsonl', ''));
74+ return [...chats];
75+ }
76+
77+ return [];
5978}
6079
6180async function getBookmarkName({ isReplace = false, forceName = null } = {}) {