mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Preserve neutral chat on reloading with commands (#2848)
* Preserve neutral chat on reloading * Restore neutral on deleting character with bulk
This commit is contained in:
@ -19,6 +19,8 @@ import {
|
||||
this_chid,
|
||||
saveChatConditional,
|
||||
chat_metadata,
|
||||
neutralCharacterName,
|
||||
updateChatMetadata,
|
||||
} from '../script.js';
|
||||
import { selected_group } from './group-chats.js';
|
||||
import { power_user } from './power-user.js';
|
||||
@ -1352,6 +1354,32 @@ async function verifyAttachmentsForSource(source) {
|
||||
}
|
||||
}
|
||||
|
||||
const NEUTRAL_CHAT_KEY = 'neutralChat';
|
||||
|
||||
export function preserveNeutralChat() {
|
||||
if (this_chid !== undefined || selected_group || name2 !== neutralCharacterName) {
|
||||
return;
|
||||
}
|
||||
|
||||
sessionStorage.setItem(NEUTRAL_CHAT_KEY, JSON.stringify({ chat, chat_metadata }));
|
||||
}
|
||||
|
||||
export function restoreNeutralChat() {
|
||||
if (this_chid !== undefined || selected_group || name2 !== neutralCharacterName) {
|
||||
return;
|
||||
}
|
||||
|
||||
const neutralChat = sessionStorage.getItem(NEUTRAL_CHAT_KEY);
|
||||
if (!neutralChat) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { chat: neutralChatData, chat_metadata: neutralChatMetadata } = JSON.parse(neutralChat);
|
||||
chat.splice(0, chat.length, ...neutralChatData);
|
||||
updateChatMetadata(neutralChatMetadata, true);
|
||||
sessionStorage.removeItem(NEUTRAL_CHAT_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a file converter function.
|
||||
* @param {string} mimeType MIME type
|
||||
|
Reference in New Issue
Block a user