diff --git a/client/js/lounge.js b/client/js/lounge.js index b67bc4eb..15b6958b 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -693,11 +693,12 @@ $(function() { chat.on("click", ".show-more-button", function() { var self = $(this); - var count = self.parent().next(".messages").children(".msg").length; + var lastMessage = self.parent().next(".messages").children(".msg").first(); + var lastMessageId = parseInt(lastMessage[0].id.replace("msg-", ""), 10); self.prop("disabled", true); socket.emit("more", { target: self.data("id"), - count: count + lastId: lastMessageId }); }); diff --git a/src/client.js b/src/client.js index a8502548..56b92dec 100644 --- a/src/client.js +++ b/src/client.js @@ -383,8 +383,8 @@ Client.prototype.more = function(data) { return; } var chan = target.chan; - var count = chan.messages.length - (data.count || 0); - var messages = chan.messages.slice(Math.max(0, count - 100), count); + var index = chan.messages.findIndex((val) => val.id === data.lastId); + var messages = chan.messages.slice(Math.max(0, index - 100), index); client.emit("more", { chan: chan.id, messages: messages