Merge pull request #1354 from thelounge/yamanickill/more-index

Change more to use id rather than count.
This commit is contained in:
Jérémie Astori 2017-07-20 01:18:52 -04:00 committed by GitHub
commit 9a5f577ae8
2 changed files with 5 additions and 4 deletions

View File

@ -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
});
});

View File

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