fix: sort before splicing when fetching messages

This commit is contained in:
Pedro Lopez 2022-02-06 20:03:59 -04:00
commit 4aae8b0f32

View file

@ -187,11 +187,13 @@ class Chat extends Base {
if (!loadedMessages) break;
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
}
if (msgs.length > searchOptions.limit)
if (msgs.length > searchOptions.limit) {
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
msgs = msgs.splice(msgs.length - searchOptions.limit);
}
}
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
return msgs.map(m => window.WWebJS.getMessageModel(m));
}, this.id._serialized, searchOptions);