Send delivery response manually

Hey,
I´m using MAM messages in my Android app and I want to send a response to a message sender, if the recipient reached the message.

If both chat partners are online, the delivery response function is working fine.
But if the message is loaded from the MAM, the delivery response doesn´t get triggered.

For this case I want to send the response manually, but I don´t know how to do it.

Can I get an example?

Thanks in advance.

I’m confused. You want to send the reponse, or handling incoming MAM messages being delivery receipts just like live delivery receipts?

I want to send a response, if the message is loaded from the MAM.

I see.

I don’t think that you should do that, as the requestor of the receipt possibly already has forgotten about it, or even worse, that he considers the receipt for another message because he re-used the stanza ID.

But if you really want to do it, the logic is simple

for (Message mamMessage : mamMessages) {
  DeliverReceiptRequest request = DeliveryReceiptRequest.from(mam-message);
  if (request == null) continue;
  Message receipt = DeliveryReceiptManager.receiptMessageFor(request);
  connection.sendStanza(receipt);
}

Of course you first have to unwrap the messages from the Forwarded.

Before, I casted the ‘ForwaredStanza’ object into a ‘Message’, because I can get the values from it,
but it is the wrong way right?

Here is my code, what I did:

return (Message) mamQueryResult.forwardedMessages.get(0).getForwardedStanza()

No, that looks correct.

Okay, but this does not work.
It seems that this is not working for messages which are loaded from the MAM, because from the OfflineMessageManager it works well.

I’m sorry, but “does not” work is not a very good problem description.

If I load the message from the MAM storage, the DeliveryReceiptManager does not automatically sends a response to the message sender.

Because if I load the message from the OfflineMessageStorage, then the response for the message is sent dirctly.

Right, that is expected behavior. I was referring to your attempt to manually send receipts for messages returned by a MAM query.

Okay, I thought that its working like to receive the message from the OfflineMessageManager.
So in this case, the solution, to send the response manually, should not run into problems?

Have a look at https://xmpp.org/extensions/xep-0013.html, xep13 offline messages are delivered in line like live messages. That triggers the deliver receipts manager automatism. Unlike xep313 messages, which are wrapped in a forwarded.

None problems besides the one I mentioned and that you should ensure to not ack a message which already got a receipt. Again, I personally would possibly not go down that route.

İm not able to send receipts for group chats. İts working fine in private chats, but the mesagges i recive through mucs do not send automatic receipts to server. İs it the case for muc messages in smack or am i missing something?

See XEP-0184 §5.3 for an explanation of Smacks behavior.

2 Likes