2017-05-18 16:08:54 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
const socket = require("../socket");
|
2018-07-08 09:42:54 -04:00
|
|
|
const {vueApp, findChannel} = require("../vue");
|
2017-05-18 16:08:54 -04:00
|
|
|
|
|
|
|
socket.on("more", function(data) {
|
2018-07-08 09:42:54 -04:00
|
|
|
let chan = $("#chat #chan-" + data.chan);
|
2017-08-24 09:50:47 -04:00
|
|
|
chan = chan.find(".messages");
|
2017-05-18 16:08:54 -04:00
|
|
|
|
|
|
|
// get the scrollable wrapper around messages
|
|
|
|
const scrollable = chan.closest(".chat");
|
2017-06-29 05:15:06 -04:00
|
|
|
const heightOld = chan.height() - scrollable.scrollTop();
|
2017-05-18 16:08:54 -04:00
|
|
|
|
2018-07-08 08:18:17 -04:00
|
|
|
const channel = findChannel(data.chan);
|
2018-02-20 02:28:04 -05:00
|
|
|
|
2018-07-08 08:18:17 -04:00
|
|
|
if (!channel) {
|
|
|
|
return;
|
2017-05-18 16:08:54 -04:00
|
|
|
}
|
|
|
|
|
2018-07-08 08:18:17 -04:00
|
|
|
channel.channel.messages.unshift(...data.messages);
|
2018-07-08 09:42:54 -04:00
|
|
|
channel.channel.historyLoading = false;
|
2017-09-12 08:40:26 -04:00
|
|
|
|
2018-07-08 09:42:54 -04:00
|
|
|
vueApp.$nextTick(() => {
|
2018-07-08 08:18:17 -04:00
|
|
|
// restore scroll position
|
|
|
|
const position = chan.height() - heightOld;
|
|
|
|
scrollable.finish().scrollTop(position);
|
|
|
|
});
|
2017-09-12 08:40:26 -04:00
|
|
|
|
2018-07-08 08:18:17 -04:00
|
|
|
if (data.messages.length !== 100) {
|
|
|
|
scrollable.find(".show-more").removeClass("show");
|
|
|
|
}
|
2017-05-18 16:08:54 -04:00
|
|
|
});
|