making showMoreMessages async to await event emission

f1923c5364d46fd6501e3c43e8697a030d22ef99

qvink <qvink@users.noreply.github.com>

3 files changed, +7 -7Ignore whitespace
public/script.js+4 -4
@@ -1830,7 +1830,7 @@ export async function replaceCurrentChat() {
1830 }1830 }
1831}1831}
18321832
1833export function showMoreMessages(messagesToLoad = null) {1833export async function showMoreMessages(messagesToLoad = null) {
1834 const firstDisplayedMesId = $('#chat').children('.mes').first().attr('mesid');1834 const firstDisplayedMesId = $('#chat').children('.mes').first().attr('mesid');
1835 let messageId = Number(firstDisplayedMesId);1835 let messageId = Number(firstDisplayedMesId);
1836 let count = messagesToLoad || power_user.chat_truncation || Number.MAX_SAFE_INTEGER;1836 let count = messagesToLoad || power_user.chat_truncation || Number.MAX_SAFE_INTEGER;
@@ -1861,7 +1861,7 @@ export function showMoreMessages(messagesToLoad = null) {
1861 $('#chat').scrollTop(newHeight - prevHeight);1861 $('#chat').scrollTop(newHeight - prevHeight);
1862 }1862 }
18631863
1864 eventSource.emit(event_types.MORE_MESSAGES_LOADED)1864 await eventSource.emit(event_types.MORE_MESSAGES_LOADED)
1865}1865}
18661866
1867export async function printMessages() {1867export async function printMessages() {
@@ -11468,8 +11468,8 @@ jQuery(async function () {
11468 $('#avatar-and-name-block').slideToggle();11468 $('#avatar-and-name-block').slideToggle();
11469 });11469 });
1147011470
11471 $(document).on('mouseup touchend', '#show_more_messages', () => {11471 $(document).on('mouseup touchend', '#show_more_messages', async function () {
11472 showMoreMessages();11472 await showMoreMessages();
11473 });11473 });
1147411474
11475 $(document).on('click', '.open_characters_library', async function () {11475 $(document).on('click', '.open_characters_library', async function () {
public/scripts/power-user.js+1 -1
@@ -2534,7 +2534,7 @@ async function loadUntilMesId(mesId) {
2534 let target;2534 let target;
25352535
2536 while (getFirstDisplayedMessageId() > mesId && getFirstDisplayedMessageId() !== 0) {2536 while (getFirstDisplayedMessageId() > mesId && getFirstDisplayedMessageId() !== 0) {
2537 showMoreMessages();2537 await showMoreMessages();
2538 await delay(1);2538 await delay(1);
2539 target = $('#chat').find(`.mes[mesid=${mesId}]`);2539 target = $('#chat').find(`.mes[mesid=${mesId}]`);
25402540
public/scripts/slash-commands.js+2 -2
@@ -1968,8 +1968,8 @@ export function initDefaultSlashCommands() {
1968 SlashCommandParser.addCommandObject(SlashCommand.fromProps({1968 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
1969 name: 'chat-render',1969 name: 'chat-render',
1970 helpString: 'Renders a specified number of messages into the chat window. Displays all messages if no argument is provided.',1970 helpString: 'Renders a specified number of messages into the chat window. Displays all messages if no argument is provided.',
1971 callback: (args, number) => {1971 callback: async (args, number) => {
1972 showMoreMessages(number && !isNaN(Number(number)) ? Number(number) : Number.MAX_SAFE_INTEGER);1972 await showMoreMessages(number && !isNaN(Number(number)) ? Number(number) : Number.MAX_SAFE_INTEGER);
1973 if (isTrueBoolean(String(args?.scroll ?? ''))) {1973 if (isTrueBoolean(String(args?.scroll ?? ''))) {
1974 $('#chat').scrollTop(0);1974 $('#chat').scrollTop(0);
1975 }1975 }