mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
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:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user