mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Save parent bookmark reference to chat metadata
This commit is contained in:
@@ -1438,8 +1438,8 @@
|
||||
<div class="group_member_icon">
|
||||
<div title="Move up" data-action="up" class="right_menu_button fa-solid fa-xl fa-chevron-up"></div>
|
||||
<div title="Move down" data-action="down" class="right_menu_button fa-solid fa-xl fa-chevron-down"></div>
|
||||
<div title="Remove from group" data-action="remove" class="right_menu_button fa-solid fa-xl fa-xmark"></div>
|
||||
<div title="Add to group" data-action="add" class="right_menu_button fa-solid fa-xl fa-plus"></div>
|
||||
<div title="Remove from group" data-action="remove" class="right_menu_button fa-solid fa-2xl fa-xmark"></div>
|
||||
<div title="Add to group" data-action="add" class="right_menu_button fa-solid fa-2xl fa-plus"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1780,7 +1780,7 @@
|
||||
<div class="options-content">
|
||||
<a id="option_back_to_main">
|
||||
<div class="fa-lg fa-solid fa-left-long"></div>
|
||||
<span>Back to main chat</span>
|
||||
<span>Back to parent chat</span>
|
||||
</a>
|
||||
<a id="option_new_bookmark">
|
||||
<div class="fa-lg fa-solid fa-bookmark"></div>
|
||||
|
@@ -2254,7 +2254,8 @@ function resultCheckStatusNovel() {
|
||||
$("#api_button_novel").css("display", "inline-block");
|
||||
}
|
||||
|
||||
async function saveChat(chat_name) {
|
||||
async function saveChat(chat_name, withMetadata) {
|
||||
const metadata = { ...chat_metadata, ...(withMetadata || {}) };
|
||||
let file_name = chat_name ?? characters[this_chid].chat;
|
||||
chat.forEach(function (item, i) {
|
||||
if (item["is_group"]) {
|
||||
@@ -2275,7 +2276,7 @@ async function saveChat(chat_name) {
|
||||
user_name: default_user_name,
|
||||
character_name: name2,
|
||||
create_date: chat_create_date,
|
||||
chat_metadata: chat_metadata,
|
||||
chat_metadata: metadata,
|
||||
},
|
||||
...chat,
|
||||
];
|
||||
|
@@ -7,6 +7,8 @@ import {
|
||||
system_message_types,
|
||||
this_chid,
|
||||
openCharacterChat,
|
||||
chat_metadata,
|
||||
callPopup,
|
||||
} from "../script.js";
|
||||
import { selected_group } from "./group-chats.js";
|
||||
|
||||
@@ -36,27 +38,40 @@ async function getExistingChatNames() {
|
||||
}
|
||||
}
|
||||
|
||||
async function getBookmarkName(currentChat) {
|
||||
async function getBookmarkName() {
|
||||
const chatNames = await getExistingChatNames();
|
||||
let mainChat = getMainChatName(currentChat);
|
||||
let newChat = Date.now();
|
||||
let friendlyName = '';
|
||||
const popupText = `<h3>Enter the bookmark name:<h3>
|
||||
<small>Using existing name will overwrite your bookmark chat.
|
||||
<br>Leave empty to auto-generate.</small>`;
|
||||
let name = await callPopup(popupText, 'input');
|
||||
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
friendlyName = `${bookmarkNameToken}${i}`;
|
||||
newChat = `${mainChat} ${friendlyName}`;
|
||||
if (!chatNames.includes(newChat)) {
|
||||
break;
|
||||
if (name === false) {
|
||||
return null;
|
||||
}
|
||||
else if (name === '') {
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
name = bookmarkNameToken + i;
|
||||
if (!chatNames.includes(name)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return { newChat, friendlyName };
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
function getMainChatName(currentChat) {
|
||||
if (currentChat.includes(bookmarkNameToken)) {
|
||||
currentChat = currentChat.substring(0, currentChat.lastIndexOf(bookmarkNameToken)).trim();
|
||||
function getMainChatName() {
|
||||
if (chat_metadata) {
|
||||
if (chat_metadata['main_chat']) {
|
||||
return chat_metadata['main_chat'];
|
||||
}
|
||||
else if (characters[this_chid].chat && characters[this_chid].chat.includes(bookmarkNameToken)) {
|
||||
const tokenIndex = characters[this_chid].chat.lastIndexOf(bookmarkNameToken);
|
||||
chat_metadata['main_chat'] = characters[this_chid].chat.substring(0, tokenIndex).trim();
|
||||
return chat_metadata['main_chat'];
|
||||
}
|
||||
}
|
||||
return currentChat;
|
||||
return null;
|
||||
}
|
||||
|
||||
function showBookmarksButtons() {
|
||||
@@ -67,7 +82,7 @@ function showBookmarksButtons() {
|
||||
$("#option_new_bookmark").hide();
|
||||
}
|
||||
// In main chat
|
||||
else if (!characters[this_chid].chat.includes(bookmarkNameToken)) {
|
||||
else if (!chat_metadata['main_chat']) {
|
||||
$("#option_back_to_main").hide();
|
||||
$("#option_new_bookmark").show();
|
||||
|
||||
@@ -91,10 +106,15 @@ $(document).ready(function () {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
let { newChat, friendlyName } = await getBookmarkName(characters[this_chid].chat);
|
||||
let name = await getBookmarkName(characters[this_chid].chat);
|
||||
|
||||
saveChat(newChat);
|
||||
let mainMessage = stringFormat(system_messages[system_message_types.BOOKMARK_CREATED].mes, newChat, friendlyName);
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newMetadata = { main_chat: characters[this_chid].chat };
|
||||
saveChat(name, newMetadata);
|
||||
let mainMessage = stringFormat(system_messages[system_message_types.BOOKMARK_CREATED].mes, name, name);
|
||||
sendSystemMessage(system_message_types.BOOKMARK_CREATED, mainMessage);
|
||||
saveChat();
|
||||
});
|
||||
|
@@ -367,6 +367,10 @@ code {
|
||||
column-gap: 10px;
|
||||
}
|
||||
|
||||
.options-content a div:first-child {
|
||||
min-width: 20px;
|
||||
}
|
||||
|
||||
.options-content img {
|
||||
width: calc(var(--mainFontSize) + .5rem);
|
||||
margin-right: 5px;
|
||||
|
Reference in New Issue
Block a user