whatsapp-web.js
whatsapp-web.js copied to clipboard
Version 1.17.1 fetchMessages({limit: 100}) only returns a subset of expected messages.
Is there an existing issue for this?
- [X] I have searched the existing issues
Describe the bug
chat.fetchMessages({limit: 100}); only returns a subset of the newest messages. The limit search option is ignored.
Expected behavior
Return every message within the limit
Steps to Reproduce the Bug or Issue
const client = new Client(); client.on('ready', async () => { console.log('Client is ready!'); var chats = await client.getChats(); var messages = await chats[5].fetchMessages({limit: 100}); client.logout() });
Relevant Code
$$$ By setting a breakpoint in my IDE at the second line the issue is resolved. There might be a timeout issue.
async fetchMessages(searchOptions) { $$$$$ let messages = await this.client.pupPage.evaluate(async (chatId, searchOptions) => { const msgFilter = m => !m.isNotification; // dont include notification messages
const chat = window.Store.Chat.get(chatId);
let msgs = chat.msgs.getModelsArray().filter(msgFilter);
if (searchOptions && searchOptions.limit > 0) {
while (msgs.length < searchOptions.limit) {
const loadedMessages = await window.Store.ConversationMsgs.loadEarlierMsgs(chat);
if (!loadedMessages || !loadedMessages.length) break;
msgs = [...loadedMessages.filter(msgFilter), ...msgs];
}
if (msgs.length > searchOptions.limit) {
msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
msgs = msgs.splice(msgs.length - searchOptions.limit);
}
}
return msgs.map(m => window.WWebJS.getMessageModel(m));
}, this.id._serialized, searchOptions);
return messages.map(m => new Message(this.client, m));
}
Browser Type
Chromium
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
Ubuntu 18 Android "whatsapp-web.js": "^1.17.1" WA Web version 2.2228.12 Node version: v12.22.12
Additional context
no
By adding a sleep timeout of 20 seconds the request works.
client.on('ready', async () => {
console.log('Client is ready!');
console.log(await client.getWWebVersion());
var chats = await client.getChats();
await new Promise(resolve => setTimeout(resolve, 20000));
var messages = await chats[5].fetchMessages({limit: 100});
client.logout()
});
Seems like it is a timeout issue where even after ready it takes a while for the messages to load.
The function should load all messages up to the limit regardless so this is weird
mismo problema.
no cargan los mensajes.
¿alguna solución?
I also have this issue...
The 20 second sleep made no difference.
Downgrading to v1.16.7 works
Any update?