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