From 29f509179cb395f4b052ce0540c634e94393fc54 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 27 Jan 2024 13:50:54 -0500 Subject: [PATCH] Remove getMessageId As far as I can tell, we don't add/remove anything from chat in between the calculation of newMessageId and subsequent calls to getMessageId. We can just use newMessageId everywhere. --- public/script.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/public/script.js b/public/script.js index 21533c4a4..22bd1c195 100644 --- a/public/script.js +++ b/public/script.js @@ -1958,16 +1958,9 @@ function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll = true } } - function getMessageId() { - if (typeof forceId == 'number') { - return forceId; - } + // Callers push the new message to chat before calling addOneMessage + const newMessageId = typeof forceId == 'number' ? forceId : chat.length - 1; - // Callers push the new message to chat before calling addOneMessage - return chat.length - 1; - } - - const newMessageId = getMessageId(); const newMessage = $(`#chat [mesid="${newMessageId}"]`); const isSmallSys = mes?.extra?.isSmallSys; newMessage.data('isSystem', isSystem); @@ -2045,7 +2038,7 @@ 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(getMessageId()); + hideSwipeButtons(newMessageId); } addCopyToCodeBlocks(newMessage); @@ -2055,8 +2048,8 @@ function addOneMessage(mes, { type = 'normal', insertAfter = null, scroll = true $('#chat .mes').last().addClass('last_mes'); $('#chat .mes').eq(-2).removeClass('last_mes'); - hideSwipeButtons(getMessageId()); - showSwipeButtons(getMessageId()); + hideSwipeButtons(newMessageId); + showSwipeButtons(newMessageId); scrollChatToBottom(); } }