Skip to content

Commit

Permalink
Merge pull request #679 from WhiskeySockets/fix-missing-messages
Browse files Browse the repository at this point in the history
Fix message retry mechanisms
  • Loading branch information
Auties00 authored Mar 19, 2024
2 parents 3663316 + 767af0b commit 1896ebe
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Socket/messages-recv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1896ebe

Please sign in to comment.