fix: correctly handle devices & encrypt notif

This commit is contained in:
Adhiraj Singh
2022-06-13 19:56:00 +05:30
parent 07f0ff86e8
commit ae94e0ac38

View File

@@ -219,7 +219,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
}
}
const processNotification = async(node: BinaryNode): Promise<Partial<proto.IWebMessageInfo>> => {
const processNotification = (node: BinaryNode) => {
const result: Partial<proto.IWebMessageInfo> = { }
const [child] = getAllBinaryNodeChildren(node)
const nodeType = node.attrs.type
@@ -289,20 +289,14 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
} else if(nodeType === 'mediaretry') {
const event = decodeMediaRetryNode(node)
ev.emit('messages.media-update', [event])
} else {
switch (child.tag) {
case 'devices':
} else if(nodeType === 'encrypt') {
handleEncryptNotification(node)
} else if(nodeType === 'devices') {
const devices = getBinaryNodeChildren(child, 'device')
if(areJidsSameUser(child.attrs.jid, authState.creds!.me!.id)) {
const deviceJids = devices.map(d => d.attrs.jid)
logger.info({ deviceJids }, 'got my own devices')
}
break
case 'encrypt':
handleEncryptNotification(node)
break
}
}
if(Object.keys(result).length) {
@@ -432,14 +426,11 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const handleNotification = async(node: BinaryNode) => {
const remoteJid = node.attrs.from
await sendMessageAck(node)
await processingMutex.mutex(
remoteJid,
async() => {
const msg = await processNotification(node)
const msg = processNotification(node)
if(msg) {
const fromMe = areJidsSameUser(node.attrs.participant || node.attrs.from, authState.creds.me!.id)
const fromMe = areJidsSameUser(node.attrs.participant || remoteJid, authState.creds.me!.id)
msg.key = {
remoteJid: node.attrs.from,
remoteJid,
fromMe,
participant: node.attrs.participant,
id: node.attrs.id,
@@ -452,8 +443,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
ev.emit('messages.upsert', { messages: [fullMsg], type: 'append' })
}
}
)
}
const handleUpsertedMessages = async({ messages, type }: BaileysEventMap<any>['messages.upsert']) => {
if(type === 'notify' || type === 'append') {