Prevent ephemeral message extra changes vanish upon swiping
| @@ -6074,6 +6074,19 @@ export async function saveReply(type, getMessage, fromStreaming, title, swipes, | ||
| 6074 | 6074 | return { type, getMessage }; |
| 6075 | 6075 | } |
| 6076 | 6076 | |
| 6077 | +export function syncCurrentSwipeInfoExtras() { | |
| 6078 | + if (!chat.length) { | |
| 6079 | + return; | |
| 6080 | + } | |
| 6081 | + const currentMessage = chat[chat.length - 1]; | |
| 6082 | + if (currentMessage && Array.isArray(currentMessage.swipe_info) && typeof currentMessage.swipe_id === 'number') { | |
| 6083 | + const swipeInfo = currentMessage.swipe_info[currentMessage.swipe_id]; | |
| 6084 | + if (swipeInfo && typeof swipeInfo === 'object') { | |
| 6085 | + swipeInfo.extra = structuredClone(currentMessage.extra); | |
| 6086 | + } | |
| 6087 | + } | |
| 6088 | +} | |
| 6089 | + | |
| 6077 | 6090 | function saveImageToMessage(img, mes) { |
| 6078 | 6091 | if (mes && img.image) { |
| 6079 | 6092 | if (!mes.extra || typeof mes.extra !== 'object') { |
| @@ -8501,6 +8514,9 @@ function swipe_left() { // when we swipe left..but no generation. | ||
| 8501 | 8514 | streamingProcessor.onStopStreaming(); |
| 8502 | 8515 | } |
| 8503 | 8516 | |
| 8517 | + // Make sure ad-hoc changes to extras are saved before swiping away | |
| 8518 | + syncCurrentSwipeInfoExtras(); | |
| 8519 | + | |
| 8504 | 8520 | const swipe_duration = 120; |
| 8505 | 8521 | const swipe_range = '700px'; |
| 8506 | 8522 | chat[chat.length - 1]['swipe_id']--; |
| @@ -8636,6 +8652,9 @@ const swipe_right = () => { | ||
| 8636 | 8652 | return unblockGeneration(); |
| 8637 | 8653 | } |
| 8638 | 8654 | |
| 8655 | + // Make sure ad-hoc changes to extras are saved before swiping away | |
| 8656 | + syncCurrentSwipeInfoExtras(); | |
| 8657 | + | |
| 8639 | 8658 | const swipe_duration = 200; |
| 8640 | 8659 | const swipe_range = 700; |
| 8641 | 8660 | //console.log(swipe_range); |
| @@ -42,6 +42,7 @@ import { | ||
| 42 | 42 | showMoreMessages, |
| 43 | 43 | stopGeneration, |
| 44 | 44 | substituteParams, |
| 45 | + syncCurrentSwipeInfoExtras, | |
| 45 | 46 | system_avatar, |
| 46 | 47 | system_message_types, |
| 47 | 48 | this_chid, |
| @@ -2814,8 +2815,11 @@ async function addSwipeCallback(args, value) { | ||
| 2814 | 2815 | const newSwipeId = lastMessage.swipes.length - 1; |
| 2815 | 2816 | |
| 2816 | 2817 | if (isTrueBoolean(args.switch)) { |
| 2818 | + // Make sure ad-hoc changes to extras are saved before swiping away | |
| 2819 | + syncCurrentSwipeInfoExtras(); | |
| 2817 | 2820 | lastMessage.swipe_id = newSwipeId; |
| 2818 | 2821 | lastMessage.mes = lastMessage.swipes[newSwipeId]; |
| 2822 | + lastMessage.extra = structuredClone(lastMessage.swipe_info?.[newSwipeId]?.extra ?? lastMessage.extra ?? {}); | |
| 2819 | 2823 | } |
| 2820 | 2824 | |
| 2821 | 2825 | await saveChatConditional(); |