fix: sort before splicing when fetching messages

This commit is contained in:
Pedro Lopez
2022-02-06 20:03:59 -04:00
parent 64803c2ba6
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);