Change more to use id rather than count.

This commit is contained in:
Alistair McKinlay 2017-07-18 21:24:02 +01:00
parent f88d1e3bef
commit e01e21cdbe
2 changed files with 5 additions and 4 deletions

View File

@ -693,11 +693,12 @@ $(function() {
chat.on("click", ".show-more-button", function() { chat.on("click", ".show-more-button", function() {
var self = $(this); 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); self.prop("disabled", true);
socket.emit("more", { socket.emit("more", {
target: self.data("id"), target: self.data("id"),
count: count lastId: lastMessageId
}); });
}); });

View File

@ -383,8 +383,8 @@ Client.prototype.more = function(data) {
return; return;
} }
var chan = target.chan; var chan = target.chan;
var count = chan.messages.length - (data.count || 0); var index = chan.messages.findIndex((val) => val.id === data.lastId);
var messages = chan.messages.slice(Math.max(0, count - 100), count); var messages = chan.messages.slice(Math.max(0, index - 100), index);
client.emit("more", { client.emit("more", {
chan: chan.id, chan: chan.id,
messages: messages messages: messages