Refactor bookmarks with correct async and export
| @@ -6,7 +6,6 @@ import { | |||
| 6 | this_chid, | 6 | this_chid, |
| 7 | openCharacterChat, | 7 | openCharacterChat, |
| 8 | chat_metadata, | 8 | chat_metadata, |
| 9 | callPopup, | ||
| 10 | getRequestHeaders, | 9 | getRequestHeaders, |
| 11 | getThumbnailUrl, | 10 | getThumbnailUrl, |
| 12 | getCharacters, | 11 | getCharacters, |
| @@ -29,15 +28,9 @@ import { Popup } from './popup.js'; | |||
| 29 | import { createTagMapFromList } from './tags.js'; | 28 | import { createTagMapFromList } from './tags.js'; |
| 30 | 29 | ||
| 31 | import { | 30 | import { |
| 32 | delay, | ||
| 33 | getUniqueName, | 31 | getUniqueName, |
| 34 | } from './utils.js'; | 32 | } from './utils.js'; |
| 35 | 33 | ||
| 36 | export { | ||
| 37 | createNewBookmark, | ||
| 38 | showBookmarksButtons, | ||
| 39 | }; | ||
| 40 | |||
| 41 | const bookmarkNameToken = 'Checkpoint #'; | 34 | const bookmarkNameToken = 'Checkpoint #'; |
| 42 | 35 | ||
| 43 | async function getExistingChatNames() { | 36 | async function getExistingChatNames() { |
| @@ -95,7 +88,7 @@ function getMainChatName() { | |||
| 95 | return null; | 88 | return null; |
| 96 | } | 89 | } |
| 97 | 90 | ||
| 98 | function showBookmarksButtons() { | 91 | export function showBookmarksButtons() { |
| 99 | try { | 92 | try { |
| 100 | if (selected_group) { | 93 | if (selected_group) { |
| 101 | $('#option_convert_to_group').hide(); | 94 | $('#option_convert_to_group').hide(); |
| @@ -130,10 +123,10 @@ async function saveBookmarkMenu() { | |||
| 130 | return; | 123 | return; |
| 131 | } | 124 | } |
| 132 | 125 | ||
| 133 | return createNewBookmark(chat.length - 1); | 126 | return await createNewBookmark(chat.length - 1); |
| 134 | } | 127 | } |
| 135 | 128 | ||
| 136 | export async function createBranch(mesId) { | 129 | async function createBranch(mesId) { |
| 137 | if (!chat.length) { | 130 | if (!chat.length) { |
| 138 | toastr.warning('The chat is empty.', 'Branch creation failed'); | 131 | toastr.warning('The chat is empty.', 'Branch creation failed'); |
| 139 | return; | 132 | return; |
| @@ -166,7 +159,7 @@ export async function createBranch(mesId) { | |||
| 166 | return name; | 159 | return name; |
| 167 | } | 160 | } |
| 168 | 161 | ||
| 169 | async function createNewBookmark(mesId) { | 162 | export async function createNewBookmark(mesId) { |
| 170 | if (this_chid === undefined && !selected_group) { | 163 | if (this_chid === undefined && !selected_group) { |
| 171 | toastr.info('No character selected.', 'Checkpoint creation aborted'); | 164 | toastr.info('No character selected.', 'Checkpoint creation aborted'); |
| 172 | return; | 165 | return; |
| @@ -243,7 +236,7 @@ async function backToMainChat() { | |||
| 243 | } | 236 | } |
| 244 | } | 237 | } |
| 245 | 238 | ||
| 246 | async function convertSoloToGroupChat() { | 239 | export async function convertSoloToGroupChat() { |
| 247 | if (selected_group) { | 240 | if (selected_group) { |
| 248 | console.log('Already in group. No need for conversion'); | 241 | console.log('Already in group. No need for conversion'); |
| 249 | return; | 242 | return; |
| @@ -270,6 +263,7 @@ async function convertSoloToGroupChat() { | |||
| 270 | const activationStrategy = group_activation_strategy.NATURAL; | 263 | const activationStrategy = group_activation_strategy.NATURAL; |
| 271 | const allowSelfResponses = false; | 264 | const allowSelfResponses = false; |
| 272 | const favChecked = character.fav || character.fav == 'true'; | 265 | const favChecked = character.fav || character.fav == 'true'; |
| 266 | /** @type {any} */ | ||
| 273 | const metadata = Object.assign({}, chat_metadata); | 267 | const metadata = Object.assign({}, chat_metadata); |
| 274 | delete metadata.main_chat; | 268 | delete metadata.main_chat; |
| 275 | 269 | ||
| @@ -365,7 +359,7 @@ async function convertSoloToGroupChat() { | |||
| 365 | * @param {number} mesId Message ID | 359 | * @param {number} mesId Message ID |
| 366 | * @returns {Promise<string>} Branch file name | 360 | * @returns {Promise<string>} Branch file name |
| 367 | */ | 361 | */ |
| 368 | async function branchChat(mesId) { | 362 | export async function branchChat(mesId) { |
| 369 | if (this_chid === undefined && !selected_group) { | 363 | if (this_chid === undefined && !selected_group) { |
| 370 | toastr.info('No character selected.', 'Branch creation aborted'); | 364 | toastr.info('No character selected.', 'Branch creation aborted'); |
| 371 | return; | 365 | return; |
| @@ -392,7 +386,7 @@ jQuery(function () { | |||
| 392 | // If shift is held down, we are not following the bookmark, but creating a new one | 386 | // If shift is held down, we are not following the bookmark, but creating a new one |
| 393 | if (e.shiftKey) { | 387 | if (e.shiftKey) { |
| 394 | var selectedMesId = $(this).closest('.mes').attr('mesid'); | 388 | var selectedMesId = $(this).closest('.mes').attr('mesid'); |
| 395 | createNewBookmark(selectedMesId); | 389 | await createNewBookmark(selectedMesId); |
| 396 | return; | 390 | return; |
| 397 | } | 391 | } |
| 398 | 392 | ||
| @@ -412,7 +406,7 @@ jQuery(function () { | |||
| 412 | await openCharacterChat(file_name); | 406 | await openCharacterChat(file_name); |
| 413 | } | 407 | } |
| 414 | } finally { | 408 | } finally { |
| 415 | hideLoader(); | 409 | await hideLoader(); |
| 416 | } | 410 | } |
| 417 | 411 | ||
| 418 | $('#shadow_select_chat_popup').css('display', 'none'); | 412 | $('#shadow_select_chat_popup').css('display', 'none'); |
| @@ -422,14 +416,14 @@ jQuery(function () { | |||
| 422 | $(document).on('click', '.mes_create_bookmark', async function () { | 416 | $(document).on('click', '.mes_create_bookmark', async function () { |
| 423 | var selected_mes_id = $(this).closest('.mes').attr('mesid'); | 417 | var selected_mes_id = $(this).closest('.mes').attr('mesid'); |
| 424 | if (selected_mes_id !== undefined) { | 418 | if (selected_mes_id !== undefined) { |
| 425 | createNewBookmark(selected_mes_id); | 419 | await createNewBookmark(selected_mes_id); |
| 426 | } | 420 | } |
| 427 | }); | 421 | }); |
| 428 | 422 | ||
| 429 | $(document).on('click', '.mes_create_branch', async function () { | 423 | $(document).on('click', '.mes_create_branch', async function () { |
| 430 | var selected_mes_id = $(this).closest('.mes').attr('mesid'); | 424 | var selected_mes_id = $(this).closest('.mes').attr('mesid'); |
| 431 | if (selected_mes_id !== undefined) { | 425 | if (selected_mes_id !== undefined) { |
| 432 | branchChat(Number(selected_mes_id)); | 426 | await branchChat(Number(selected_mes_id)); |
| 433 | } | 427 | } |
| 434 | }); | 428 | }); |
| 435 | }); | 429 | }); |