Skip to content

Commit

Permalink
fix: Improved speed of loadAndGetAllMessagesInChat function (fix #166)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed May 7, 2021
1 parent 5200970 commit 7f1348a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/lib/wapi/functions/load-all-earlier-chat-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,26 @@
*/

export async function loadAllEarlierMessages(id, done) {
const found = WAPI.getChat(id);
while (!found.msgs.msgLoadState.noEarlierMsgs) {
console.log('Loading...');
await found.loadEarlierMsgs();
const chat = WAPI.getChat(id);

if (!chat) {
done && done(false);
return false;
}
console.log('done');

// improve load speed
try {
await Store.Msg.findQuery({
remote: chat.id,
count: -1,
});
} catch (error) {}

while (!chat.msgs.msgLoadState.noEarlierMsgs) {
await chat.loadEarlierMsgs();
}

done && done(true);
return true;
}

Expand Down

0 comments on commit 7f1348a

Please sign in to comment.