mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
loadMessages bug fix
This commit is contained in:
@@ -116,13 +116,14 @@ WAConnectionTest('Misc', (conn) => {
|
|||||||
assert.ok (response.messages.length >= 0)
|
assert.ok (response.messages.length >= 0)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should load a single message', async () => {
|
it('should load a single message', async () => {
|
||||||
const {messages} = await conn.loadMessages (testJid, 10)
|
const {messages} = await conn.loadMessages (testJid, 25)
|
||||||
for (var message of messages) {
|
for (var message of messages) {
|
||||||
const loaded = await conn.loadMessage (testJid, message.key.id)
|
const loaded = await conn.loadMessage (testJid, message.key.id)
|
||||||
assert.equal (loaded.key.id, message.key.id)
|
assert.equal (loaded.key.id, message.key.id, `loaded message ${JSON.stringify(message)} incorrectly`)
|
||||||
await delay (1000)
|
await delay (500)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should update presence', async () => {
|
it('should update presence', async () => {
|
||||||
|
|||||||
@@ -147,12 +147,10 @@ export class WAConnection extends Base {
|
|||||||
}
|
}
|
||||||
/** Load a single message specified by the ID */
|
/** Load a single message specified by the ID */
|
||||||
async loadMessage (jid: string, messageID: string) {
|
async loadMessage (jid: string, messageID: string) {
|
||||||
let messages: WAMessage[]
|
// load the message before the given message
|
||||||
try {
|
let messages = (await this.loadMessages (jid, 1, {id: messageID, fromMe: true})).messages
|
||||||
messages = (await this.loadMessages (jid, 1, {id: messageID, fromMe: true})).messages
|
if (!messages[0]) messages = (await this.loadMessages (jid, 1, {id: messageID, fromMe: false})).messages
|
||||||
} catch {
|
// the message after the loaded message is the message required
|
||||||
messages = (await this.loadMessages (jid, 1, {id: messageID, fromMe: false})).messages
|
|
||||||
}
|
|
||||||
const actual = await this.loadMessages (jid, 1, messages[0] && messages[0].key, false)
|
const actual = await this.loadMessages (jid, 1, messages[0] && messages[0].key, false)
|
||||||
return actual.messages[0]
|
return actual.messages[0]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user