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 {
14} from '../script.js';14} from '../script.js';
15import { humanizedDateTime } from './RossAscends-mods.js';15import { humanizedDateTime } from './RossAscends-mods.js';
16import {16import {
17 getGroupPastChats,
18 group_activation_strategy,17 group_activation_strategy,
19 groups,18 groups,
20 openGroupById,19 openGroupById,
@@ -40,22 +39,42 @@ import {
4039
41const bookmarkNameToken = 'Checkpoint #';40const 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 */
43async function getExistingChatNames() {46async function getExistingChatNames() {
44 if (selected_group) {47 if (selected_group) {
45 const data = await getGroupPastChats(selected_group);48 const group = groups.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', ''));
57 }51 }
52
53 return [];
58 }54 }
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 [];
59}78}
6079
61async function getBookmarkName({ isReplace = false, forceName = null } = {}) {80async function getBookmarkName({ isReplace = false, forceName = null } = {}) {