fix: correctly splice and merge fetched messages

This was eliminating messages in the middle of the array instead of eliminating older messages to reach the specified limit.

close #97
This commit is contained in:
Pedro Lopez
2020-03-05 21:18:10 -04:00
parent d7a3e1a9a3
commit 49aacec4a7

View File

@@ -131,14 +131,14 @@ class Chat extends Base {
while(msgs.length < limit) {
const loadedMessages = await chat.loadEarlierMsgs();
if(!loadedMessages) break;
msgs = [...msgs, ...loadedMessages.filter(msgFilter)];
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
}
return msgs.splice(0, limit).map(m => m.serialize());
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
return msgs.splice(msgs.length - limit).map(m => m.serialize());
}, this.id._serialized, searchOptions.limit);
messages.sort((a, b) => (a.t > b.t) ? 1 : -1);
return messages.map(m => new Message(this.client, m));
}