mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Refactor bookmarks with correct async and export
This commit is contained in:
@ -6,7 +6,6 @@ import {
|
|||||||
this_chid,
|
this_chid,
|
||||||
openCharacterChat,
|
openCharacterChat,
|
||||||
chat_metadata,
|
chat_metadata,
|
||||||
callPopup,
|
|
||||||
getRequestHeaders,
|
getRequestHeaders,
|
||||||
getThumbnailUrl,
|
getThumbnailUrl,
|
||||||
getCharacters,
|
getCharacters,
|
||||||
@ -29,15 +28,9 @@ import { Popup } from './popup.js';
|
|||||||
import { createTagMapFromList } from './tags.js';
|
import { createTagMapFromList } from './tags.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
delay,
|
|
||||||
getUniqueName,
|
getUniqueName,
|
||||||
} from './utils.js';
|
} from './utils.js';
|
||||||
|
|
||||||
export {
|
|
||||||
createNewBookmark,
|
|
||||||
showBookmarksButtons,
|
|
||||||
};
|
|
||||||
|
|
||||||
const bookmarkNameToken = 'Checkpoint #';
|
const bookmarkNameToken = 'Checkpoint #';
|
||||||
|
|
||||||
async function getExistingChatNames() {
|
async function getExistingChatNames() {
|
||||||
@ -95,7 +88,7 @@ function getMainChatName() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showBookmarksButtons() {
|
export function showBookmarksButtons() {
|
||||||
try {
|
try {
|
||||||
if (selected_group) {
|
if (selected_group) {
|
||||||
$('#option_convert_to_group').hide();
|
$('#option_convert_to_group').hide();
|
||||||
@ -130,10 +123,10 @@ async function saveBookmarkMenu() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return createNewBookmark(chat.length - 1);
|
return await createNewBookmark(chat.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createBranch(mesId) {
|
async function createBranch(mesId) {
|
||||||
if (!chat.length) {
|
if (!chat.length) {
|
||||||
toastr.warning('The chat is empty.', 'Branch creation failed');
|
toastr.warning('The chat is empty.', 'Branch creation failed');
|
||||||
return;
|
return;
|
||||||
@ -166,7 +159,7 @@ export async function createBranch(mesId) {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createNewBookmark(mesId) {
|
export async function createNewBookmark(mesId) {
|
||||||
if (this_chid === undefined && !selected_group) {
|
if (this_chid === undefined && !selected_group) {
|
||||||
toastr.info('No character selected.', 'Checkpoint creation aborted');
|
toastr.info('No character selected.', 'Checkpoint creation aborted');
|
||||||
return;
|
return;
|
||||||
@ -243,7 +236,7 @@ async function backToMainChat() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function convertSoloToGroupChat() {
|
export async function convertSoloToGroupChat() {
|
||||||
if (selected_group) {
|
if (selected_group) {
|
||||||
console.log('Already in group. No need for conversion');
|
console.log('Already in group. No need for conversion');
|
||||||
return;
|
return;
|
||||||
@ -270,6 +263,7 @@ async function convertSoloToGroupChat() {
|
|||||||
const activationStrategy = group_activation_strategy.NATURAL;
|
const activationStrategy = group_activation_strategy.NATURAL;
|
||||||
const allowSelfResponses = false;
|
const allowSelfResponses = false;
|
||||||
const favChecked = character.fav || character.fav == 'true';
|
const favChecked = character.fav || character.fav == 'true';
|
||||||
|
/** @type {any} */
|
||||||
const metadata = Object.assign({}, chat_metadata);
|
const metadata = Object.assign({}, chat_metadata);
|
||||||
delete metadata.main_chat;
|
delete metadata.main_chat;
|
||||||
|
|
||||||
@ -365,7 +359,7 @@ async function convertSoloToGroupChat() {
|
|||||||
* @param {number} mesId Message ID
|
* @param {number} mesId Message ID
|
||||||
* @returns {Promise<string>} Branch file name
|
* @returns {Promise<string>} Branch file name
|
||||||
*/
|
*/
|
||||||
async function branchChat(mesId) {
|
export async function branchChat(mesId) {
|
||||||
if (this_chid === undefined && !selected_group) {
|
if (this_chid === undefined && !selected_group) {
|
||||||
toastr.info('No character selected.', 'Branch creation aborted');
|
toastr.info('No character selected.', 'Branch creation aborted');
|
||||||
return;
|
return;
|
||||||
@ -392,7 +386,7 @@ jQuery(function () {
|
|||||||
// If shift is held down, we are not following the bookmark, but creating a new one
|
// If shift is held down, we are not following the bookmark, but creating a new one
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
var selectedMesId = $(this).closest('.mes').attr('mesid');
|
var selectedMesId = $(this).closest('.mes').attr('mesid');
|
||||||
createNewBookmark(selectedMesId);
|
await createNewBookmark(selectedMesId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,7 +406,7 @@ jQuery(function () {
|
|||||||
await openCharacterChat(file_name);
|
await openCharacterChat(file_name);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
hideLoader();
|
await hideLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#shadow_select_chat_popup').css('display', 'none');
|
$('#shadow_select_chat_popup').css('display', 'none');
|
||||||
@ -422,14 +416,14 @@ jQuery(function () {
|
|||||||
$(document).on('click', '.mes_create_bookmark', async function () {
|
$(document).on('click', '.mes_create_bookmark', async function () {
|
||||||
var selected_mes_id = $(this).closest('.mes').attr('mesid');
|
var selected_mes_id = $(this).closest('.mes').attr('mesid');
|
||||||
if (selected_mes_id !== undefined) {
|
if (selected_mes_id !== undefined) {
|
||||||
createNewBookmark(selected_mes_id);
|
await createNewBookmark(selected_mes_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', '.mes_create_branch', async function () {
|
$(document).on('click', '.mes_create_branch', async function () {
|
||||||
var selected_mes_id = $(this).closest('.mes').attr('mesid');
|
var selected_mes_id = $(this).closest('.mes').attr('mesid');
|
||||||
if (selected_mes_id !== undefined) {
|
if (selected_mes_id !== undefined) {
|
||||||
branchChat(Number(selected_mes_id));
|
await branchChat(Number(selected_mes_id));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user