diff --git a/public/script.js b/public/script.js index 2bbc88c9e..3ba3aacbc 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', @@ -1829,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; @@ -1859,6 +1860,8 @@ export function showMoreMessages(messagesToLoad = null) { const newHeight = $('#chat').prop('scrollHeight'); $('#chat').scrollTop(newHeight - prevHeight); } + + await eventSource.emit(event_types.MORE_MESSAGES_LOADED); } export async function printMessages() { @@ -11465,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); }