Refactor bookmarks with correct async and export

cb9e73decaa808a85306ca59f26b6211a085a254

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +11 -17Showing whitespace changes
public/scripts/bookmarks.js+11 -17
@@ -6,7 +6,6 @@ import {
66 this_chid,
77 openCharacterChat,
88 chat_metadata,
9- callPopup,
109 getRequestHeaders,
1110 getThumbnailUrl,
1211 getCharacters,
@@ -29,15 +28,9 @@ import { Popup } from './popup.js';
2928import { createTagMapFromList } from './tags.js';
3029
3130import {
32- delay,
3331 getUniqueName,
3432} from './utils.js';
3533
36-export {
37- createNewBookmark,
38- showBookmarksButtons,
39-};
40-
4134const bookmarkNameToken = 'Checkpoint #';
4235
4336async function getExistingChatNames() {
@@ -95,7 +88,7 @@ function getMainChatName() {
9588 return null;
9689}
9790
9891export function showBookmarksButtons() {
9992 try {
10093 if (selected_group) {
10194 $('#option_convert_to_group').hide();
@@ -130,10 +123,10 @@ async function saveBookmarkMenu() {
130123 return;
131124 }
132125
133126 return await createNewBookmark(chat.length - 1);
134127}
135128
136129export async function createBranch(mesId) {
137130 if (!chat.length) {
138131 toastr.warning('The chat is empty.', 'Branch creation failed');
139132 return;
@@ -166,7 +159,7 @@ export async function createBranch(mesId) {
166159 return name;
167160}
168161
169162export async function createNewBookmark(mesId) {
170163 if (this_chid === undefined && !selected_group) {
171164 toastr.info('No character selected.', 'Checkpoint creation aborted');
172165 return;
@@ -243,7 +236,7 @@ async function backToMainChat() {
243236 }
244237}
245238
246239export async function convertSoloToGroupChat() {
247240 if (selected_group) {
248241 console.log('Already in group. No need for conversion');
249242 return;
@@ -270,6 +263,7 @@ async function convertSoloToGroupChat() {
270263 const activationStrategy = group_activation_strategy.NATURAL;
271264 const allowSelfResponses = false;
272265 const favChecked = character.fav || character.fav == 'true';
266+ /** @type {any} */
273267 const metadata = Object.assign({}, chat_metadata);
274268 delete metadata.main_chat;
275269
@@ -365,7 +359,7 @@ async function convertSoloToGroupChat() {
365359 * @param {number} mesId Message ID
366360 * @returns {Promise<string>} Branch file name
367361 */
368362export async function branchChat(mesId) {
369363 if (this_chid === undefined && !selected_group) {
370364 toastr.info('No character selected.', 'Branch creation aborted');
371365 return;
@@ -392,7 +386,7 @@ jQuery(function () {
392386 // If shift is held down, we are not following the bookmark, but creating a new one
393387 if (e.shiftKey) {
394388 var selectedMesId = $(this).closest('.mes').attr('mesid');
395389 await createNewBookmark(selectedMesId);
396390 return;
397391 }
398392
@@ -412,7 +406,7 @@ jQuery(function () {
412406 await openCharacterChat(file_name);
413407 }
414408 } finally {
415409 await hideLoader();
416410 }
417411
418412 $('#shadow_select_chat_popup').css('display', 'none');
@@ -422,14 +416,14 @@ jQuery(function () {
422416 $(document).on('click', '.mes_create_bookmark', async function () {
423417 var selected_mes_id = $(this).closest('.mes').attr('mesid');
424418 if (selected_mes_id !== undefined) {
425419 await createNewBookmark(selected_mes_id);
426420 }
427421 });
428422
429423 $(document).on('click', '.mes_create_branch', async function () {
430424 var selected_mes_id = $(this).closest('.mes').attr('mesid');
431425 if (selected_mes_id !== undefined) {
432426 await branchChat(Number(selected_mes_id));
433427 }
434428 });
435429});