Cancel debounced chat save if regular save is performed
| @@ -6436,6 +6436,7 @@ export function saveChatDebounced() { | |||
| 6436 | if (chatSaveTimeout) { | 6436 | if (chatSaveTimeout) { |
| 6437 | console.debug('Clearing chat save timeout'); | 6437 | console.debug('Clearing chat save timeout'); |
| 6438 | clearTimeout(chatSaveTimeout); | 6438 | clearTimeout(chatSaveTimeout); |
| 6439 | chatSaveTimeout = null; | ||
| 6439 | } | 6440 | } |
| 6440 | 6441 | ||
| 6441 | chatSaveTimeout = setTimeout(async () => { | 6442 | chatSaveTimeout = setTimeout(async () => { |
| @@ -6452,7 +6453,7 @@ export function saveChatDebounced() { | |||
| 6452 | console.debug('Chat save timeout triggered'); | 6453 | console.debug('Chat save timeout triggered'); |
| 6453 | await saveChatConditional(); | 6454 | await saveChatConditional(); |
| 6454 | console.debug('Chat saved'); | 6455 | console.debug('Chat saved'); |
| 6455 | }, 1000); | 6456 | }, DEFAULT_SAVE_EDIT_TIMEOUT); |
| 6456 | } | 6457 | } |
| 6457 | 6458 | ||
| 6458 | export async function saveChat(chatName, withMetadata, mesId) { | 6459 | export async function saveChat(chatName, withMetadata, mesId) { |
| @@ -8067,6 +8068,12 @@ export async function saveChatConditional() { | |||
| 8067 | } | 8068 | } |
| 8068 | 8069 | ||
| 8069 | try { | 8070 | try { |
| 8071 | if (chatSaveTimeout) { | ||
| 8072 | console.debug('Debounced chat save canceled'); | ||
| 8073 | clearTimeout(chatSaveTimeout); | ||
| 8074 | chatSaveTimeout = null; | ||
| 8075 | } | ||
| 8076 | |||
| 8070 | isChatSaving = true; | 8077 | isChatSaving = true; |
| 8071 | 8078 | ||
| 8072 | if (selected_group) { | 8079 | if (selected_group) { |
| @@ -1048,7 +1048,7 @@ function registerReasoningAppEvents() { | |||
| 1048 | 1048 | ||
| 1049 | if (contentUpdated) { | 1049 | if (contentUpdated) { |
| 1050 | syncMesToSwipe(); | 1050 | syncMesToSwipe(); |
| 1051 | await saveChatConditional(); | 1051 | saveChatDebounced(); |
| 1052 | 1052 | ||
| 1053 | // Find if a message already exists in DOM and must be updated | 1053 | // Find if a message already exists in DOM and must be updated |
| 1054 | const messageRendered = document.querySelector(`.mes[mesid="${idx}"]`) !== null; | 1054 | const messageRendered = document.querySelector(`.mes[mesid="${idx}"]`) !== null; |