diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 33aed5c..575263d 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -81,7 +81,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { let sendActiveReceipts = false - const sendMessageAck = async({ tag, attrs }: BinaryNode) => { + const sendMessageAck = async({ tag, attrs, content }: BinaryNode) => { const stanza: BinaryNode = { tag: 'ack', attrs: { @@ -99,9 +99,14 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { stanza.attrs.recipient = attrs.recipient } - if(tag !== 'message' && attrs.type) { - stanza.attrs.type = attrs.type - } + + if(!!attrs.type && (tag !== 'message' || getBinaryNodeChild({ tag, attrs, content }, 'unavailable'))) { + stanza.attrs.type = attrs.type + } + + if(tag === 'message' && getBinaryNodeChild({ tag, attrs, content }, 'unavailable')) { + stanza.attrs.from = authState.creds.me!.id + } logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack') await sendNode(stanza) @@ -678,6 +683,13 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } const handleMessage = async(node: BinaryNode) => { + if(getBinaryNodeChild(node, 'unavailable') && !getBinaryNodeChild(node, 'enc')) { + // "missing message from node" fix + logger.debug(node, 'missing body; sending ack then ignoring.') + await sendMessageAck(node) + return + } + const { fullMessage: msg, category, author, decrypt } = decryptMessageNode( node, authState.creds.me!.id,