mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: call processInBuffer for all msg handling
This commit is contained in:
@@ -617,17 +617,16 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
}
|
||||
}
|
||||
|
||||
const flushBufferIfLastOfflineNode = (
|
||||
/// processes a node with the given function
|
||||
/// and adds the task to the existing buffer if we're buffering events
|
||||
const processNodeWithBuffer = (
|
||||
node: BinaryNode,
|
||||
identifier: string,
|
||||
exec: (node: BinaryNode) => Promise<any>
|
||||
) => {
|
||||
const task = exec(node)
|
||||
.catch(err => onUnexpectedError(err, identifier))
|
||||
const offline = node.attrs.offline
|
||||
if(offline) {
|
||||
ev.processInBuffer(task)
|
||||
}
|
||||
ev.processInBuffer(task)
|
||||
}
|
||||
|
||||
// called when all offline notifs are handled
|
||||
@@ -643,19 +642,19 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
||||
|
||||
// recv a message
|
||||
ws.on('CB:message', (node: BinaryNode) => {
|
||||
flushBufferIfLastOfflineNode(node, 'processing message', handleMessage)
|
||||
processNodeWithBuffer(node, 'processing message', handleMessage)
|
||||
})
|
||||
|
||||
ws.on('CB:call', async(node: BinaryNode) => {
|
||||
flushBufferIfLastOfflineNode(node, 'handling call', handleCall)
|
||||
processNodeWithBuffer(node, 'handling call', handleCall)
|
||||
})
|
||||
|
||||
ws.on('CB:receipt', node => {
|
||||
flushBufferIfLastOfflineNode(node, 'handling receipt', handleReceipt)
|
||||
processNodeWithBuffer(node, 'handling receipt', handleReceipt)
|
||||
})
|
||||
|
||||
ws.on('CB:notification', async(node: BinaryNode) => {
|
||||
flushBufferIfLastOfflineNode(node, 'handling notification', handleNotification)
|
||||
processNodeWithBuffer(node, 'handling notification', handleNotification)
|
||||
})
|
||||
|
||||
ws.on('CB:ack,class:message', (node: BinaryNode) => {
|
||||
|
||||
Reference in New Issue
Block a user