mirror of
https://github.com/thelounge/thelounge
synced 2024-11-26 14:00:21 +00:00
parent
15b922595f
commit
14cac93e10
2 changed files with 19 additions and 8 deletions
|
@ -56,12 +56,13 @@ socket.on("more", function(data) {
|
|||
});
|
||||
|
||||
chat.on("click", ".show-more-button", function() {
|
||||
var self = $(this);
|
||||
var lastMessage = self.parent().next(".messages").children(".msg").first();
|
||||
if (lastMessage.is(".condensed")) {
|
||||
lastMessage = lastMessage.children(".msg").first();
|
||||
const self = $(this);
|
||||
const lastMessage = self.closest(".chat").find(".msg").first();
|
||||
let lastMessageId = -1;
|
||||
|
||||
if (lastMessage.length > 0) {
|
||||
lastMessageId = parseInt(lastMessage[0].id.replace("msg-", ""), 10);
|
||||
}
|
||||
var lastMessageId = parseInt(lastMessage[0].id.replace("msg-", ""), 10);
|
||||
|
||||
self
|
||||
.text("Loading older messages…")
|
||||
|
|
|
@ -412,10 +412,20 @@ Client.prototype.more = function(data) {
|
|||
}
|
||||
|
||||
const chan = target.chan;
|
||||
const index = chan.messages.findIndex((val) => val.id === data.lastId);
|
||||
let messages = [];
|
||||
let index = 0;
|
||||
|
||||
// If we don't find the requested message, send an empty array
|
||||
const messages = index > 0 ? chan.messages.slice(Math.max(0, index - 100), index) : [];
|
||||
// If client requests -1, send last 100 messages
|
||||
if (data.lastId < 0) {
|
||||
index = chan.messages.length;
|
||||
} else {
|
||||
index = chan.messages.findIndex((val) => val.id === data.lastId);
|
||||
}
|
||||
|
||||
// If requested id is not found, an empty array will be sent
|
||||
if (index > 0) {
|
||||
messages = chan.messages.slice(Math.max(0, index - 100), index);
|
||||
}
|
||||
|
||||
client.emit("more", {
|
||||
chan: chan.id,
|
||||
|
|
Loading…
Reference in a new issue