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() {
|
chat.on("click", ".show-more-button", function() {
|
||||||
var self = $(this);
|
const self = $(this);
|
||||||
var lastMessage = self.parent().next(".messages").children(".msg").first();
|
const lastMessage = self.closest(".chat").find(".msg").first();
|
||||||
if (lastMessage.is(".condensed")) {
|
let lastMessageId = -1;
|
||||||
lastMessage = lastMessage.children(".msg").first();
|
|
||||||
|
if (lastMessage.length > 0) {
|
||||||
|
lastMessageId = parseInt(lastMessage[0].id.replace("msg-", ""), 10);
|
||||||
}
|
}
|
||||||
var lastMessageId = parseInt(lastMessage[0].id.replace("msg-", ""), 10);
|
|
||||||
|
|
||||||
self
|
self
|
||||||
.text("Loading older messages…")
|
.text("Loading older messages…")
|
||||||
|
|
|
@ -412,10 +412,20 @@ Client.prototype.more = function(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const chan = target.chan;
|
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
|
// If client requests -1, send last 100 messages
|
||||||
const messages = index > 0 ? chan.messages.slice(Math.max(0, index - 100), index) : [];
|
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", {
|
client.emit("more", {
|
||||||
chan: chan.id,
|
chan: chan.id,
|
||||||
|
|
Loading…
Reference in a new issue