mirror of
https://github.com/thelounge/thelounge
synced 2024-11-23 04:23:13 +00:00
30 lines
780 B
JavaScript
30 lines
780 B
JavaScript
"use strict";
|
|
|
|
const $ = require("jquery");
|
|
const socket = require("../socket");
|
|
const {vueApp, findChannel} = require("../vue");
|
|
|
|
socket.on("more", function(data) {
|
|
let chan = $("#chat #chan-" + data.chan);
|
|
chan = chan.find(".messages");
|
|
|
|
// get the scrollable wrapper around messages
|
|
const scrollable = chan.closest(".chat");
|
|
const heightOld = chan.height() - scrollable.scrollTop();
|
|
|
|
const channel = findChannel(data.chan);
|
|
|
|
if (!channel) {
|
|
return;
|
|
}
|
|
|
|
channel.channel.moreHistoryAvailable = data.moreHistoryAvailable;
|
|
channel.channel.messages.unshift(...data.messages);
|
|
channel.channel.historyLoading = false;
|
|
|
|
vueApp.$nextTick(() => {
|
|
// restore scroll position
|
|
const position = chan.height() - heightOld;
|
|
scrollable.finish().scrollTop(position);
|
|
});
|
|
});
|