From ef9cdf64cfc60b86cfa21fbc1a705dcf67001dda Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 29 Jan 2024 00:37:51 +0200 Subject: [PATCH] Fix swipe buttons display when using /comment after last AI message --- public/script.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/public/script.js b/public/script.js index b410625b5..6193b5b54 100644 --- a/public/script.js +++ b/public/script.js @@ -2035,18 +2035,19 @@ function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll = true const messageId = forceId ?? chat.length - 1; $('#chat').find(`[mesid="${messageId}"]`).find('.mes_text').append(messageText); appendMediaToMessage(mes, newMessage); - hideSwipeButtons(newMessageId); + hideSwipeButtons(); } addCopyToCodeBlocks(newMessage); + $('#chat .mes').last().addClass('last_mes'); + $('#chat .mes').eq(-2).removeClass('last_mes'); + + hideSwipeButtons(); + showSwipeButtons(); + // Don't scroll if not inserting last if (!insertAfter && !insertBefore && scroll) { - $('#chat .mes').last().addClass('last_mes'); - $('#chat .mes').eq(-2).removeClass('last_mes'); - - hideSwipeButtons(newMessageId); - showSwipeButtons(newMessageId); scrollChatToBottom(); } } @@ -6475,7 +6476,7 @@ function callPopup(text, type, inputValue = '', { okButton, rows, wide, large } }); } -function showSwipeButtons(id = chat.length - 1) { +function showSwipeButtons() { if (chat.length === 0) { return; } @@ -6483,10 +6484,9 @@ function showSwipeButtons(id = chat.length - 1) { if ( chat[chat.length - 1].is_system || !swipes || - $('.mes:last').attr('mesid') < 0 || + Number($('.mes:last').attr('mesid')) < 0 || chat[chat.length - 1].is_user || chat[chat.length - 1].extra?.image || - id < 0 || (selected_group && is_group_generating) ) { return; } @@ -6505,7 +6505,7 @@ function showSwipeButtons(id = chat.length - 1) { chat[chat.length - 1]['swipes'][0] = chat[chat.length - 1]['mes']; //assign swipe array with last message from chat } - const currentMessage = $('#chat').children().filter(`[mesid="${id}"]`); + const currentMessage = $('#chat').children().filter(`[mesid="${chat.length - 1}"]`); const swipeId = chat[chat.length - 1].swipe_id; var swipesCounterHTML = (`${(swipeId + 1)}/${(chat[chat.length - 1].swipes.length)}`); @@ -6530,10 +6530,10 @@ function showSwipeButtons(id = chat.length - 1) { //console.log(chat[chat.length - 1].swipes.length); } -function hideSwipeButtons(id = chat.length - 1) { +function hideSwipeButtons() { //console.log('hideswipebuttons entered'); - $('#chat').children().filter(`[mesid="${id}"]`).children('.swipe_right').css('display', 'none'); - $('#chat').children().filter(`[mesid="${id}"]`).children('.swipe_left').css('display', 'none'); + $('#chat').find('.swipe_right').css('display', 'none'); + $('#chat').find('.swipe_left').css('display', 'none'); } export async function saveMetadata() {