Allow message swipe gens with image attachments (#4184) * Allow message swipe gens with image attachments * Replace JSON.parse with structuredClone
Signed| @@ -2496,6 +2496,11 @@ export function appendMediaToMessage(mes, messageElement, adjustScroll = true) { | ||
| 2496 | 2496 | eventSource.emit(event_types.IMAGE_SWIPED, { message: mes, element: messageElement, direction: 'right' }); |
| 2497 | 2497 | }); |
| 2498 | 2498 | } |
| 2499 | + } else { | |
| 2500 | + const container = messageElement.find('.mes_img_container'); | |
| 2501 | + container.removeClass('img_extra img_swipes'); | |
| 2502 | + const text = messageElement.find('.mes_text'); | |
| 2503 | + text.removeClass('displayNone'); | |
| 2499 | 2504 | } |
| 2500 | 2505 | |
| 2501 | 2506 | // Add video to message |
| @@ -2521,6 +2526,8 @@ export function appendMediaToMessage(mes, messageElement, adjustScroll = true) { | ||
| 2521 | 2526 | }); |
| 2522 | 2527 | |
| 2523 | 2528 | video.attr('src', mes.extra?.video); |
| 2529 | + } else { | |
| 2530 | + messageElement.find('.mes_video').remove(); | |
| 2524 | 2531 | } |
| 2525 | 2532 | |
| 2526 | 2533 | // Add file to message |
| @@ -3561,7 +3568,7 @@ class StreamingProcessor { | ||
| 3561 | 3568 | 'send_date': chat[messageId]['send_date'], |
| 3562 | 3569 | 'gen_started': chat[messageId]['gen_started'], |
| 3563 | 3570 | 'gen_finished': chat[messageId]['gen_finished'], |
| 3564 | 3571 | 'extra': JSON.parse(JSON.stringifystructuredClone(chat[messageId]['extra'])), |
| 3565 | 3572 | }; |
| 3566 | 3573 | } |
| 3567 | 3574 | |
| @@ -3666,7 +3673,7 @@ class StreamingProcessor { | ||
| 3666 | 3673 | 'send_date': chat[messageId]['send_date'], |
| 3667 | 3674 | 'gen_started': chat[messageId]['gen_started'], |
| 3668 | 3675 | 'gen_finished': chat[messageId]['gen_finished'], |
| 3669 | 3676 | 'extra': JSON.parse(JSON.stringifystructuredClone(chat[messageId]['extra'])), |
| 3670 | 3677 | }; |
| 3671 | 3678 | } |
| 3672 | 3679 | } |
| @@ -6551,7 +6558,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title | ||
| 6551 | 6558 | send_date: item['send_date'], |
| 6552 | 6559 | gen_started: item['gen_started'], |
| 6553 | 6560 | gen_finished: item['gen_finished'], |
| 6554 | 6561 | extra: JSON.parse(JSON.stringifystructuredClone(item['extra'])), |
| 6555 | 6562 | }; |
| 6556 | 6563 | } else { |
| 6557 | 6564 | item['swipe_id'] = 0; |
| @@ -6561,7 +6568,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title | ||
| 6561 | 6568 | send_date: chat[chat.length - 1]['send_date'], |
| 6562 | 6569 | gen_started: chat[chat.length - 1]['gen_started'], |
| 6563 | 6570 | gen_finished: chat[chat.length - 1]['gen_finished'], |
| 6564 | 6571 | extra: JSON.parse(JSON.stringifystructuredClone(chat[chat.length - 1]['extra'])), |
| 6565 | 6572 | }; |
| 6566 | 6573 | } |
| 6567 | 6574 | |
| @@ -8649,7 +8656,6 @@ export function showSwipeButtons() { | ||
| 8649 | 8656 | !swipes || |
| 8650 | 8657 | Number($('.mes:last').attr('mesid')) < 0 || |
| 8651 | 8658 | chat[chat.length - 1].is_user || |
| 8652 | - chat[chat.length - 1].extra?.image || | |
| 8653 | 8659 | (selected_group && is_group_generating) |
| 8654 | 8660 | ) { return; } |
| 8655 | 8661 | |
| @@ -8665,6 +8671,13 @@ export function showSwipeButtons() { | ||
| 8665 | 8671 | chat[chat.length - 1]['swipe_id'] = 0; // set it to id 0 |
| 8666 | 8672 | chat[chat.length - 1]['swipes'] = []; // empty the array |
| 8667 | 8673 | chat[chat.length - 1]['swipes'][0] = chat[chat.length - 1]['mes']; //assign swipe array with last message from chat |
| 8674 | + chat[chat.length - 1]['swipe_info'] = []; | |
| 8675 | + chat[chat.length - 1]['swipe_info'][0] = { | |
| 8676 | + 'send_date': chat[chat.length - 1]['send_date'], | |
| 8677 | + 'gen_started': chat[chat.length - 1]['gen_started'], | |
| 8678 | + 'gen_finished': chat[chat.length - 1]['gen_finished'], | |
| 8679 | + 'extra': structuredClone(chat[chat.length - 1]['extra']), | |
| 8680 | + }; | |
| 8668 | 8681 | } |
| 8669 | 8682 | |
| 8670 | 8683 | const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`); |
| @@ -9339,7 +9352,7 @@ export function swipe_left(_event, { source, repeated } = {}) { | ||
| 9339 | 9352 | const this_mes_block_height = this_mes_block[0].scrollHeight; |
| 9340 | 9353 | chat[chat.length - 1]['mes'] = chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipe_id']]; |
| 9341 | 9354 | chat[chat.length - 1]['send_date'] = chat[chat.length - 1].swipe_info[chat[chat.length - 1]['swipe_id']]?.send_date || chat[chat.length - 1].send_date; //load the last mes box with the latest generation |
| 9342 | 9355 | chat[chat.length - 1]['extra'] = JSON.parse(JSON.stringifystructuredClone(chat[chat.length - 1].swipe_info[chat[chat.length - 1]['swipe_id']]?.extra || chat[chat.length - 1].extra)); |
| 9343 | 9356 | |
| 9344 | 9357 | if (chat[chat.length - 1].extra) { |
| 9345 | 9358 | // if message has memory attached - remove it to allow regen |
| @@ -9401,6 +9414,7 @@ export function swipe_left(_event, { source, repeated } = {}) { | ||
| 9401 | 9414 | easing: animation_easing, |
| 9402 | 9415 | queue: false, |
| 9403 | 9416 | complete: async function () { |
| 9417 | + appendMediaToMessage(chat[chat.length - 1], $(this).parent().children('.mes_block')); | |
| 9404 | 9418 | await eventSource.emit(event_types.MESSAGE_SWIPED, (chat.length - 1)); |
| 9405 | 9419 | saveChatDebounced(); |
| 9406 | 9420 | }, |
| @@ -9476,7 +9490,7 @@ export function swipe_right(_event = null, { source, repeated } = {}) { | ||
| 9476 | 9490 | 'send_date': chat[chat.length - 1]['send_date'], |
| 9477 | 9491 | 'gen_started': chat[chat.length - 1]['gen_started'], |
| 9478 | 9492 | 'gen_finished': chat[chat.length - 1]['gen_finished'], |
| 9479 | 9493 | 'extra': JSON.parse(JSON.stringifystructuredClone(chat[chat.length - 1]['extra'])), |
| 9480 | 9494 | }; |
| 9481 | 9495 | //assign swipe info array with last message from chat |
| 9482 | 9496 | } |
| @@ -9500,6 +9514,11 @@ export function swipe_right(_event = null, { source, repeated } = {}) { | ||
| 9500 | 9514 | if (chat[chat.length - 1].extra.display_text) { |
| 9501 | 9515 | delete chat[chat.length - 1].extra.display_text; |
| 9502 | 9516 | } |
| 9517 | + | |
| 9518 | + delete chat[chat.length - 1].extra.image; | |
| 9519 | + delete chat[chat.length - 1].extra.image_swipes; | |
| 9520 | + delete chat[chat.length - 1].extra.video; | |
| 9521 | + delete chat[chat.length - 1].extra.inline_image; | |
| 9503 | 9522 | } |
| 9504 | 9523 | if (!Array.isArray(chat[chat.length - 1]['swipe_info'])) { |
| 9505 | 9524 | chat[chat.length - 1]['swipe_info'] = []; |
| @@ -9512,7 +9531,7 @@ export function swipe_right(_event = null, { source, repeated } = {}) { | ||
| 9512 | 9531 | } else if (parseInt(chat[chat.length - 1]['swipe_id']) < chat[chat.length - 1]['swipes'].length) { //otherwise, if the id is less than the number of swipes |
| 9513 | 9532 | chat[chat.length - 1]['mes'] = chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipe_id']]; //load the last mes box with the latest generation |
| 9514 | 9533 | chat[chat.length - 1]['send_date'] = chat[chat.length - 1]?.swipe_info[chat[chat.length - 1]['swipe_id']]?.send_date || chat[chat.length - 1]['send_date']; //update send date |
| 9515 | 9534 | chat[chat.length - 1]['extra'] = JSON.parse(JSON.stringifystructuredClone(chat[chat.length - 1].swipe_info[chat[chat.length - 1]['swipe_id']]?.extra || chat[chat.length - 1].extra || [])); |
| 9516 | 9535 | run_swipe_right = true; //then prepare to do normal right swipe to show next message |
| 9517 | 9536 | } |
| 9518 | 9537 | |
| @@ -9595,6 +9614,7 @@ export function swipe_right(_event = null, { source, repeated } = {}) { | ||
| 9595 | 9614 | easing: animation_easing, |
| 9596 | 9615 | queue: false, |
| 9597 | 9616 | complete: async function () { |
| 9617 | + appendMediaToMessage(chat[chat.length - 1], swipeMessage); | |
| 9598 | 9618 | await eventSource.emit(event_types.MESSAGE_SWIPED, (chat.length - 1)); |
| 9599 | 9619 | if (run_generate && !is_send_press && parseInt(chat[chat.length - 1]['swipe_id']) === chat[chat.length - 1]['swipes'].length) { |
| 9600 | 9620 | console.debug('caught here 2'); |