mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Removed deprecations + merge message-status-update into chat-update
1. Update package version to 4.0.0 2. Retry query if the connection unexpectedly closes + make query iterative instead of recursive 3. Remove message-new & message-update deprecations 4. Deprecate loadProfilePicturesForChatsAutomatically
This commit is contained in:
@@ -372,4 +372,21 @@ describe ('Pending Requests', () => {
|
||||
|
||||
conn.close ()
|
||||
})
|
||||
it('should re-execute query on connection closed error', async () => {
|
||||
const conn = makeConnection ()
|
||||
//conn.pendingRequestTimeoutMs = 10_000
|
||||
await conn.loadAuthInfo('./auth_info.json').connect ()
|
||||
const task: Promise<any> = conn.query({json: ['query', 'Status', conn.user.jid], waitForOpen: true})
|
||||
|
||||
await delay(20)
|
||||
conn['onMessageRecieved']('1234,["Pong",false]') // fake cancel the connection
|
||||
|
||||
await delay(2000)
|
||||
|
||||
const json = await task
|
||||
|
||||
assert.ok (json.status)
|
||||
|
||||
conn.close ()
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MessageType, Mimetype, delay, promiseTimeout, WA_MESSAGE_STATUS_TYPE, WAMessageStatusUpdate } from '../WAConnection/WAConnection'
|
||||
import { MessageType, Mimetype, delay, promiseTimeout, WA_MESSAGE_STATUS_TYPE, WAMessageStatusUpdate, generateMessageID, WAMessage } from '../WAConnection/WAConnection'
|
||||
import {promises as fs} from 'fs'
|
||||
import * as assert from 'assert'
|
||||
import { WAConnectionTest, testJid, sendAndRetreiveMessage, assertChatDBIntegrity } from './Common'
|
||||
@@ -168,17 +168,23 @@ WAConnectionTest('Messages', conn => {
|
||||
const content2 = await fs.readFile('./Media/cat.jpeg')
|
||||
await sendAndRetreiveMessage(conn, content2, MessageType.image)
|
||||
})
|
||||
it('should fail to send a text message', done => {
|
||||
it('should fail to send a text message', async () => {
|
||||
const JID = '1234-1234@g.us'
|
||||
conn.sendMessage(JID, 'hello', MessageType.text)
|
||||
const messageId = generateMessageID()
|
||||
conn.sendMessage(JID, 'hello', MessageType.text, { messageId })
|
||||
|
||||
conn.on ('message-status-update', async update => {
|
||||
if (update.to === JID) {
|
||||
assert.strictEqual (update.type, WA_MESSAGE_STATUS_TYPE.ERROR)
|
||||
await conn.deleteChat (JID)
|
||||
done ()
|
||||
}
|
||||
})
|
||||
await new Promise(resolve => (
|
||||
conn.on ('chat-update', async update => {
|
||||
console.log(messageId, update.messages?.first)
|
||||
if (
|
||||
update.jid === JID &&
|
||||
update.messages?.first.key.id === messageId &&
|
||||
update.messages.first.status === WA_MESSAGE_STATUS_TYPE.ERROR) {
|
||||
resolve(undefined)
|
||||
}
|
||||
})
|
||||
))
|
||||
conn.removeAllListeners('chat-update')
|
||||
})
|
||||
it('should maintain message integrity', async () => {
|
||||
// loading twice does not alter the results
|
||||
@@ -236,16 +242,17 @@ WAConnectionTest('Messages', conn => {
|
||||
}
|
||||
})
|
||||
it('should deliver a message', async () => {
|
||||
const response = await conn.sendMessage(testJid, 'My Name Jeff', MessageType.text)
|
||||
const waitForUpdate =
|
||||
promiseTimeout(15000, resolve => {
|
||||
conn.on('message-status-update', update => {
|
||||
if (update.ids.includes(response.key.id)) {
|
||||
resolve(update)
|
||||
conn.on('chat-update', update => {
|
||||
if (update.messages?.first.key.id === response.key.id) {
|
||||
resolve(update.messages.first)
|
||||
}
|
||||
})
|
||||
}) as Promise<WAMessageStatusUpdate>
|
||||
const response = await conn.sendMessage(testJid, 'My Name Jeff', MessageType.text)
|
||||
}) as Promise<WAMessage>
|
||||
|
||||
const m = await waitForUpdate
|
||||
assert.ok (m.type >= WA_MESSAGE_STATUS_TYPE.DELIVERY_ACK)
|
||||
assert.ok (m.status >= WA_MESSAGE_STATUS_TYPE.DELIVERY_ACK)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -171,7 +171,7 @@ WAConnectionTest('Misc', conn => {
|
||||
await delay (2000)
|
||||
await conn.modifyChat (testJid, ChatModification.unmute)
|
||||
})
|
||||
it('should star/unchar messages', async () => {
|
||||
it('should star/unstar messages', async () => {
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
await conn.sendMessage(testJid, `Message ${i}`, MessageType.text)
|
||||
await delay(1000)
|
||||
@@ -276,7 +276,7 @@ WAConnectionTest('Misc', conn => {
|
||||
it('should detect overlaps and clear messages accordingly', async () => {
|
||||
// wait for chats
|
||||
await new Promise(resolve => (
|
||||
conn.once('chats-received', ({ hasReceivedLastMessage }) => hasReceivedLastMessage && resolve(undefined))
|
||||
conn.once('initial-data-received', resolve)
|
||||
))
|
||||
|
||||
conn.maxCachedMessages = 100
|
||||
@@ -293,18 +293,16 @@ WAConnectionTest('Misc', conn => {
|
||||
chat.messages = newMessagesDB( chat.messages.all().slice(0, 20) )
|
||||
|
||||
const task = new Promise(resolve => (
|
||||
conn.on('chats-received', ({ hasReceivedLastMessage, chatsWithMissingMessages }) => {
|
||||
if (hasReceivedLastMessage) {
|
||||
assert.strictEqual(Object.keys(chatsWithMissingMessages).length, 1)
|
||||
const missing = chatsWithMissingMessages.find(({ jid }) => jid === testJid)
|
||||
assert.ok(missing, 'missing message not detected')
|
||||
assert.strictEqual(
|
||||
conn.chats.get(testJid).messages.length,
|
||||
missing.count
|
||||
)
|
||||
assert.strictEqual(missing.count, oldCount)
|
||||
resolve(undefined)
|
||||
}
|
||||
conn.on('initial-data-received', ({ chatsWithMissingMessages }) => {
|
||||
assert.strictEqual(Object.keys(chatsWithMissingMessages).length, 1)
|
||||
const missing = chatsWithMissingMessages.find(({ jid }) => jid === testJid)
|
||||
assert.ok(missing, 'missing message not detected')
|
||||
assert.strictEqual(
|
||||
conn.chats.get(testJid).messages.length,
|
||||
missing.count
|
||||
)
|
||||
assert.strictEqual(missing.count, oldCount)
|
||||
resolve(undefined)
|
||||
})
|
||||
))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user