From 1641b1f91f015481d4186dca1c66df370969766d Mon Sep 17 00:00:00 2001 From: qvink Date: Tue, 21 Jan 2025 22:14:35 -0700 Subject: [PATCH 1/3] adding event after loading more messages in chat --- public/script.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/script.js b/public/script.js index 2bbc88c9e..3e92c154b 100644 --- a/public/script.js +++ b/public/script.js @@ -443,6 +443,7 @@ export const event_types = { MESSAGE_DELETED: 'message_deleted', MESSAGE_UPDATED: 'message_updated', MESSAGE_FILE_EMBEDDED: 'message_file_embedded', + MORE_MESSAGES_LOADED: 'more_messages_loaded', IMPERSONATE_READY: 'impersonate_ready', CHAT_CHANGED: 'chat_id_changed', GENERATION_AFTER_COMMANDS: 'GENERATION_AFTER_COMMANDS', @@ -1859,6 +1860,8 @@ export function showMoreMessages(messagesToLoad = null) { const newHeight = $('#chat').prop('scrollHeight'); $('#chat').scrollTop(newHeight - prevHeight); } + + eventSource.emit(event_types.MORE_MESSAGES_LOADED) } export async function printMessages() { From f1923c5364d46fd6501e3c43e8697a030d22ef99 Mon Sep 17 00:00:00 2001 From: qvink Date: Wed, 22 Jan 2025 08:36:47 -0700 Subject: [PATCH 2/3] making showMoreMessages async to await event emission --- public/script.js | 8 ++++---- public/scripts/power-user.js | 2 +- public/scripts/slash-commands.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/public/script.js b/public/script.js index 3e92c154b..f2e84f21d 100644 --- a/public/script.js +++ b/public/script.js @@ -1830,7 +1830,7 @@ export async function replaceCurrentChat() { } } -export function showMoreMessages(messagesToLoad = null) { +export async function showMoreMessages(messagesToLoad = null) { const firstDisplayedMesId = $('#chat').children('.mes').first().attr('mesid'); let messageId = Number(firstDisplayedMesId); let count = messagesToLoad || power_user.chat_truncation || Number.MAX_SAFE_INTEGER; @@ -1861,7 +1861,7 @@ export function showMoreMessages(messagesToLoad = null) { $('#chat').scrollTop(newHeight - prevHeight); } - eventSource.emit(event_types.MORE_MESSAGES_LOADED) + await eventSource.emit(event_types.MORE_MESSAGES_LOADED) } export async function printMessages() { @@ -11468,8 +11468,8 @@ jQuery(async function () { $('#avatar-and-name-block').slideToggle(); }); - $(document).on('mouseup touchend', '#show_more_messages', () => { - showMoreMessages(); + $(document).on('mouseup touchend', '#show_more_messages', async function () { + await showMoreMessages(); }); $(document).on('click', '.open_characters_library', async function () { diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index b3b7f41d5..bfe8eca2e 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -2534,7 +2534,7 @@ async function loadUntilMesId(mesId) { let target; while (getFirstDisplayedMessageId() > mesId && getFirstDisplayedMessageId() !== 0) { - showMoreMessages(); + await showMoreMessages(); await delay(1); target = $('#chat').find(`.mes[mesid=${mesId}]`); diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 33725bf2d..39b3db71e 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -1968,8 +1968,8 @@ export function initDefaultSlashCommands() { SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'chat-render', helpString: 'Renders a specified number of messages into the chat window. Displays all messages if no argument is provided.', - callback: (args, number) => { - showMoreMessages(number && !isNaN(Number(number)) ? Number(number) : Number.MAX_SAFE_INTEGER); + callback: async (args, number) => { + await showMoreMessages(number && !isNaN(Number(number)) ? Number(number) : Number.MAX_SAFE_INTEGER); if (isTrueBoolean(String(args?.scroll ?? ''))) { $('#chat').scrollTop(0); } From 8f18d351098425cdb437e62df8e041200c1c2aeb Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:18:34 +0000 Subject: [PATCH 3/3] [chore] Add missing semi --- public/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index f2e84f21d..3ba3aacbc 100644 --- a/public/script.js +++ b/public/script.js @@ -1861,7 +1861,7 @@ export async function showMoreMessages(messagesToLoad = null) { $('#chat').scrollTop(newHeight - prevHeight); } - await eventSource.emit(event_types.MORE_MESSAGES_LOADED) + await eventSource.emit(event_types.MORE_MESSAGES_LOADED); } export async function printMessages() {