mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-02 20:36:49 +01:00
Persist active chat across devices.
This commit is contained in:
parent
314b194891
commit
6829f5308f
@ -737,6 +737,9 @@ let token;
|
||||
|
||||
var PromptArrayItemForRawPromptDisplay;
|
||||
|
||||
export let active_character = ""
|
||||
export let active_group = ""
|
||||
|
||||
export function getRequestHeaders() {
|
||||
return {
|
||||
"Content-Type": "application/json",
|
||||
@ -786,6 +789,14 @@ function checkOnlineStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
export function setActiveCharacter(character) {
|
||||
active_character = character;
|
||||
}
|
||||
|
||||
export function setActiveGroup(group) {
|
||||
active_group = group;
|
||||
}
|
||||
|
||||
async function getStatus() {
|
||||
if (is_get_status) {
|
||||
if (main_api == "koboldhorde") {
|
||||
@ -5009,6 +5020,10 @@ async function getSettings(type) {
|
||||
highlightSelectedAvatar();
|
||||
setPersonaDescription();
|
||||
|
||||
//Load the active character and group
|
||||
active_character = settings.active_character;
|
||||
active_group = settings.active_group;
|
||||
|
||||
//Load the API server URL from settings
|
||||
api_server = settings.api_server;
|
||||
$("#api_url_text").val(api_server);
|
||||
@ -5049,6 +5064,8 @@ async function saveSettings(type) {
|
||||
data: JSON.stringify({
|
||||
firstRun: firstRun,
|
||||
username: name1,
|
||||
active_character: active_character,
|
||||
active_group: active_group,
|
||||
api_server: api_server,
|
||||
api_server_textgenerationwebui: api_server_textgenerationwebui,
|
||||
preset_settings: preset_settings,
|
||||
|
@ -13,6 +13,10 @@ import {
|
||||
menu_type,
|
||||
max_context,
|
||||
saveSettingsDebounced,
|
||||
active_group,
|
||||
active_character,
|
||||
setActiveGroup,
|
||||
setActiveCharacter,
|
||||
} from "../script.js";
|
||||
|
||||
import {
|
||||
@ -330,11 +334,23 @@ export function RA_CountCharTokens() {
|
||||
characterStatsHandler(characters, this_chid);
|
||||
});
|
||||
}
|
||||
//Auto Load Last Charcter -- (fires when active_character is defined and auto_load_chat is true)
|
||||
/**
|
||||
* Auto load chat with the last active character or group.
|
||||
* Fires when active_character is defined and auto_load_chat is true.
|
||||
* The function first tries to find a character with a specific ID from the global settings.
|
||||
* If it doesn't exist, it tries to find a group with a specific grid from the global settings.
|
||||
* If the character list hadn't been loaded yet, it calls itself again after 100ms delay.
|
||||
* The character or group is selected (clicked) if it is found.
|
||||
*/
|
||||
async function RA_autoloadchat() {
|
||||
if (document.getElementById('CharID0') !== null) {
|
||||
var charToAutoLoad = document.getElementById('CharID' + LoadLocal('ActiveChar'));
|
||||
let groupToAutoLoad = document.querySelector(`.group_select[grid="${LoadLocal('ActiveGroup')}"]`);
|
||||
// active character is the name, we should look it up in the character list and get the id
|
||||
let active_character_id = Object.keys(characters).find(key => characters[key].avatar === active_character);
|
||||
// active group is the name, we should look it up in the group list and get the id
|
||||
let active_group_id = groups.find(x => x.name === active_group)?.id;
|
||||
|
||||
var charToAutoLoad = document.getElementById('CharID' + active_character_id);
|
||||
let groupToAutoLoad = document.querySelector(`.group_select[grid="${active_group_id}"]`);
|
||||
if (charToAutoLoad != null) {
|
||||
$(charToAutoLoad).click();
|
||||
}
|
||||
@ -342,7 +358,7 @@ async function RA_autoloadchat() {
|
||||
$(groupToAutoLoad).click();
|
||||
}
|
||||
|
||||
// if the charcter list hadn't been loaded yet, try again.
|
||||
// if the character list hadn't been loaded yet, try again.
|
||||
} else { setTimeout(RA_autoloadchat, 100); }
|
||||
}
|
||||
|
||||
@ -903,16 +919,20 @@ $("document").ready(function () {
|
||||
$("#rm_button_characters").click(function () { SaveLocal('SelectedNavTab', 'rm_button_characters'); });
|
||||
|
||||
// when a char is selected from the list, save them as the auto-load character for next page load
|
||||
|
||||
// when a char is selected from the list, save their name as the auto-load character for next page load
|
||||
$(document).on("click", ".character_select", function () {
|
||||
SaveLocal('ActiveChar', $(this).attr('chid'));
|
||||
SaveLocal('ActiveGroup', null);
|
||||
setActiveCharacter($(this).find('.avatar').attr('title'));
|
||||
setActiveGroup(null);
|
||||
});
|
||||
|
||||
$(document).on("click", ".group_select", function () {
|
||||
SaveLocal('ActiveChar', null);
|
||||
SaveLocal('ActiveGroup', $(this).data('id'));
|
||||
setActiveCharacter(null);
|
||||
setActiveGroup($(this).data('id'));
|
||||
});
|
||||
|
||||
|
||||
|
||||
//this makes the chat input text area resize vertically to match the text size (limited by CSS at 50% window height)
|
||||
$('#send_textarea').on('input', function () {
|
||||
this.style.height = '40px';
|
||||
|
Loading…
x
Reference in New Issue
Block a user