Add lazy chat messages rendering

This commit is contained in:
Cohee1207
2023-08-12 13:10:41 +03:00
parent 2a1eb029a2
commit 82f6d11795
3 changed files with 44 additions and 0 deletions

View File

@ -1193,6 +1193,16 @@ function printMessages() {
chat.forEach(function (item, i, arr) {
addOneMessage(item, { scroll: i === arr.length - 1 });
});
if (power_user.lazy_load > 0) {
const height = $('#chat').height();
const scrollHeight = $('#chat').prop('scrollHeight');
// Only hide if oveflowing the scroll
if (scrollHeight > height) {
$('#chat').children('.mes').slice(0, -power_user.lazy_load).hide();
}
}
}
function clearChat() {
@ -7144,6 +7154,17 @@ $(document).ready(function () {
updateVisibleDivs('#rm_print_characters_block', true);
}, 5));
$('#chat').on('scroll', async () => {
// if on the start of the chat and has hidden messages
if ($('#chat').scrollTop() === 0 && $('#chat').children('.mes').not(':visible').length > 0) {
// show next hidden messages
const prevHeight = $('#chat').prop('scrollHeight');
$('#chat').children('.mes').not(':visible').slice(-power_user.lazy_load).show();
const newHeight = $('#chat').prop('scrollHeight');
$('#chat').scrollTop(newHeight - prevHeight);
}
});
$("#chat").on('mousewheel touchstart', () => {
scrollLock = true;
});