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 result: Partial<proto.IWebMessageInfo> = { }
const [child] = getAllBinaryNodeChildren(node) const [child] = getAllBinaryNodeChildren(node)
const nodeType = node.attrs.type const nodeType = node.attrs.type
@@ -289,19 +289,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
} else if(nodeType === 'mediaretry') { } else if(nodeType === 'mediaretry') {
const event = decodeMediaRetryNode(node) const event = decodeMediaRetryNode(node)
ev.emit('messages.media-update', [event]) ev.emit('messages.media-update', [event])
} else { } else if(nodeType === 'encrypt') {
switch (child.tag) { handleEncryptNotification(node)
case 'devices': } else if(nodeType === 'devices') {
const devices = getBinaryNodeChildren(child, 'device') const devices = getBinaryNodeChildren(child, 'device')
if(areJidsSameUser(child.attrs.jid, authState.creds!.me!.id)) { if(areJidsSameUser(child.attrs.jid, authState.creds!.me!.id)) {
const deviceJids = devices.map(d => d.attrs.jid) const deviceJids = devices.map(d => d.attrs.jid)
logger.info({ deviceJids }, 'got my own devices') logger.info({ deviceJids }, 'got my own devices')
}
break
case 'encrypt':
handleEncryptNotification(node)
break
} }
} }
@@ -432,27 +426,22 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const handleNotification = async(node: BinaryNode) => { const handleNotification = async(node: BinaryNode) => {
const remoteJid = node.attrs.from const remoteJid = node.attrs.from
await sendMessageAck(node) await sendMessageAck(node)
await processingMutex.mutex( const msg = processNotification(node)
remoteJid, if(msg) {
async() => { const fromMe = areJidsSameUser(node.attrs.participant || remoteJid, authState.creds.me!.id)
const msg = await processNotification(node) msg.key = {
if(msg) { remoteJid,
const fromMe = areJidsSameUser(node.attrs.participant || node.attrs.from, authState.creds.me!.id) fromMe,
msg.key = { participant: node.attrs.participant,
remoteJid: node.attrs.from, id: node.attrs.id,
fromMe, ...(msg.key || {})
participant: node.attrs.participant,
id: node.attrs.id,
...(msg.key || {})
}
msg.participant = node.attrs.participant
msg.messageTimestamp = +node.attrs.t
const fullMsg = proto.WebMessageInfo.fromObject(msg)
ev.emit('messages.upsert', { messages: [fullMsg], type: 'append' })
}
} }
) msg.participant = node.attrs.participant
msg.messageTimestamp = +node.attrs.t
const fullMsg = proto.WebMessageInfo.fromObject(msg)
ev.emit('messages.upsert', { messages: [fullMsg], type: 'append' })
}
} }
const handleUpsertedMessages = async({ messages, type }: BaileysEventMap<any>['messages.upsert']) => { const handleUpsertedMessages = async({ messages, type }: BaileysEventMap<any>['messages.upsert']) => {