Cancel debounced chat save if regular save is performed

This commit is contained in:
Cohee
2025-02-25 21:38:24 +02:00
parent 5545a425ea
commit 422517ec93
2 changed files with 9 additions and 2 deletions

View File

@ -6436,6 +6436,7 @@ export function saveChatDebounced() {
if (chatSaveTimeout) { if (chatSaveTimeout) {
console.debug('Clearing chat save timeout'); console.debug('Clearing chat save timeout');
clearTimeout(chatSaveTimeout); clearTimeout(chatSaveTimeout);
chatSaveTimeout = null;
} }
chatSaveTimeout = setTimeout(async () => { chatSaveTimeout = setTimeout(async () => {
@ -6452,7 +6453,7 @@ export function saveChatDebounced() {
console.debug('Chat save timeout triggered'); console.debug('Chat save timeout triggered');
await saveChatConditional(); await saveChatConditional();
console.debug('Chat saved'); console.debug('Chat saved');
}, 1000); }, DEFAULT_SAVE_EDIT_TIMEOUT);
} }
export async function saveChat(chatName, withMetadata, mesId) { export async function saveChat(chatName, withMetadata, mesId) {
@ -8067,6 +8068,12 @@ export async function saveChatConditional() {
} }
try { try {
if (chatSaveTimeout) {
console.debug('Debounced chat save canceled');
clearTimeout(chatSaveTimeout);
chatSaveTimeout = null;
}
isChatSaving = true; isChatSaving = true;
if (selected_group) { if (selected_group) {

View File

@ -1048,7 +1048,7 @@ function registerReasoningAppEvents() {
if (contentUpdated) { if (contentUpdated) {
syncMesToSwipe(); syncMesToSwipe();
await saveChatConditional(); saveChatDebounced();
// Find if a message already exists in DOM and must be updated // Find if a message already exists in DOM and must be updated
const messageRendered = document.querySelector(`.mes[mesid="${idx}"]`) !== null; const messageRendered = document.querySelector(`.mes[mesid="${idx}"]`) !== null;