Flowdalic/smack — pull request #18 by ge0rg (2013-02-03 13:41:50+00:00)
Title: Implement XEP-0184 delivery notifications

*for master branch: revert 0b1c5ac449c1438e39a89823bb4d43bc56b67124, then apply this patch.*

This patch provides three components required to implement XEP-0184:

* DeliveryReceiptRequest is a PacketExtension to request a receipt
* DeliveryReceipt is a PacketExtension that contains the receipt
* DeliveryReceiptManager to handle sending/receiving of requests and
receipts.

Implementation:

For requesting a receipt, just add a new DeliveryReceiptRequest() to
your message or use the helper function:

DeliveryReceiptManager.addDeliveryReceiptRequest(packet);

Register a ReceiptReceivedListener to find out if your packet arrived:

DeliveryReceiptManager.getInstanceFor(myConnection)
.registerReceiptReceivedListener(new ReceiptReceivedListener() {
@Override public void onReceiptReceived(String fromJid,
String toJid, String receiptId) {
// receipt received for packet id receiptId
}

To answer a receipt request, you can either check incoming packets
manually:

if (DeliveryReceiptManager.hasDeliveryReceiptRequest(packet)) {
// send receipt
}

Or you can enable automatic receipt transmission with:

DeliveryReceiptManager.getInstanceFor(myConnection)
.setAutoReceiptsEnabled(true);

Signed-Off-By: Georg Lukas