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:
Cohee
2024-09-16 00:38:41 +03:00
committed by GitHub
parent 5bbc3ea758
commit 08f2b73ab8
2 changed files with 37 additions and 10 deletions

View File

@ -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