Merge pull request #3331 from qvink/emit_event_on_load_messages adding event after loading more messages in chat

a2f71d387fde9946e192165cd15c7afadc54b71b

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
3 files changed, +9 -6Showing whitespace changes
public/script.js+6 -3
@@ -443,6 +443,7 @@ export const event_types = {
443443 MESSAGE_DELETED: 'message_deleted',
444444 MESSAGE_UPDATED: 'message_updated',
445445 MESSAGE_FILE_EMBEDDED: 'message_file_embedded',
446+ MORE_MESSAGES_LOADED: 'more_messages_loaded',
446447 IMPERSONATE_READY: 'impersonate_ready',
447448 CHAT_CHANGED: 'chat_id_changed',
448449 GENERATION_AFTER_COMMANDS: 'GENERATION_AFTER_COMMANDS',
@@ -1829,7 +1830,7 @@ export async function replaceCurrentChat() {
18291830 }
18301831}
18311832
18321833export async function showMoreMessages(messagesToLoad = null) {
18331834 const firstDisplayedMesId = $('#chat').children('.mes').first().attr('mesid');
18341835 let messageId = Number(firstDisplayedMesId);
18351836 let count = messagesToLoad || power_user.chat_truncation || Number.MAX_SAFE_INTEGER;
@@ -1859,6 +1860,8 @@ export function showMoreMessages(messagesToLoad = null) {
18591860 const newHeight = $('#chat').prop('scrollHeight');
18601861 $('#chat').scrollTop(newHeight - prevHeight);
18611862 }
1863+
1864+ await eventSource.emit(event_types.MORE_MESSAGES_LOADED);
18621865}
18631866
18641867export async function printMessages() {
@@ -11465,8 +11468,8 @@ jQuery(async function () {
1146511468 $('#avatar-and-name-block').slideToggle();
1146611469 });
1146711470
1146811471 $(document).on('mouseup touchend', '#show_more_messages', async function () => {
1146911472 await showMoreMessages();
1147011473 });
1147111474
1147211475 $(document).on('click', '.open_characters_library', async function () {
public/scripts/power-user.js+1 -1
@@ -2534,7 +2534,7 @@ async function loadUntilMesId(mesId) {
25342534 let target;
25352535
25362536 while (getFirstDisplayedMessageId() > mesId && getFirstDisplayedMessageId() !== 0) {
25372537 await showMoreMessages();
25382538 await delay(1);
25392539 target = $('#chat').find(`.mes[mesid=${mesId}]`);
25402540
public/scripts/slash-commands.js+2 -2
@@ -1968,8 +1968,8 @@ export function initDefaultSlashCommands() {
19681968 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
19691969 name: 'chat-render',
19701970 helpString: 'Renders a specified number of messages into the chat window. Displays all messages if no argument is provided.',
19711971 callback: async (args, number) => {
19721972 await showMoreMessages(number && !isNaN(Number(number)) ? Number(number) : Number.MAX_SAFE_INTEGER);
19731973 if (isTrueBoolean(String(args?.scroll ?? ''))) {
19741974 $('#chat').scrollTop(0);
19751975 }