From 4aae8b0f32fe276aa5cf0ef890b94984ef0db371 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Sun, 6 Feb 2022 20:03:59 -0400 Subject: [PATCH] fix: sort before splicing when fetching messages --- src/structures/Chat.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/structures/Chat.js b/src/structures/Chat.js index 01eec83..20aa7dc 100644 --- a/src/structures/Chat.js +++ b/src/structures/Chat.js @@ -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);