hardlounge/client/js/socket-events/more.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-05-18 20:08:54 +00:00
"use strict";
const $ = require("jquery");
const socket = require("../socket");
const condensed = require("../condensed");
2018-07-08 13:42:54 +00:00
const {vueApp, findChannel} = require("../vue");
2017-05-18 20:08:54 +00:00
socket.on("more", function(data) {
2018-07-08 13:42:54 +00:00
let chan = $("#chat #chan-" + data.chan);
chan = chan.find(".messages");
2017-05-18 20:08:54 +00:00
// get the scrollable wrapper around messages
const scrollable = chan.closest(".chat");
const heightOld = chan.height() - scrollable.scrollTop();
2017-05-18 20:08:54 +00:00
const channel = findChannel(data.chan);
if (!channel) {
return;
2017-05-18 20:08:54 +00:00
}
channel.channel.messages.unshift(...data.messages);
2018-07-08 13:42:54 +00:00
channel.channel.historyLoading = false;
2018-07-08 13:42:54 +00:00
vueApp.$nextTick(() => {
// restore scroll position
const position = chan.height() - heightOld;
scrollable.finish().scrollTop(position);
});
if (data.messages.length !== 100) {
scrollable.find(".show-more").removeClass("show");
}
return;
2017-05-18 20:08:54 +00:00
// Join duplicate condensed messages together
const condensedDuplicate = chan.find(".msg.condensed + .msg.condensed");
if (condensedDuplicate) {
const condensedCorrect = condensedDuplicate.prev();
condensed.updateText(condensedCorrect, condensed.getStoredTypes(condensedDuplicate));
condensedCorrect
.append(condensedDuplicate.find(".msg"))
.toggleClass("closed", condensedDuplicate.hasClass("closed"));
condensedDuplicate.remove();
}
2017-05-18 20:08:54 +00:00
});