Merge pull request #1519 from thelounge/xpaw/fix-show-more-when-empty

Fix requesting last messages when no message id is known
This commit is contained in:
Al McKinlay 2017-09-14 07:25:17 +01:00 committed by GitHub
commit 171449c81e
2 changed files with 19 additions and 8 deletions

View File

@ -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…")

View File

@ -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,