From 387be5bded39754a89b2a83596a15cfc2767c9e1 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 5 Oct 2014 16:46:39 +0200 Subject: [PATCH] Add DeliveryReceiptRequest.addTo(Message) --- .../smackx/receipts/DeliveryReceiptManager.java | 5 +++-- .../smackx/receipts/DeliveryReceiptRequest.java | 15 +++++++++++++++ .../smackx/receipts/DeliveryReceiptTest.java | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java index 44dff1eef..93f088b8a 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java @@ -188,9 +188,10 @@ public class DeliveryReceiptManager extends Manager implements PacketListener { * * @param m Message object to add a request to * @return the Message ID which will be used as receipt ID + * @deprecated use {@link DeliveryReceiptRequest#addTo(Message)} */ + @Deprecated public static String addDeliveryReceiptRequest(Message m) { - m.addExtension(new DeliveryReceiptRequest()); - return m.getPacketID(); + return DeliveryReceiptRequest.addTo(m); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptRequest.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptRequest.java index dd1953129..0d04affcb 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptRequest.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/receipts/DeliveryReceiptRequest.java @@ -16,6 +16,7 @@ */ package org.jivesoftware.smackx.receipts; +import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.provider.PacketExtensionProvider; @@ -68,6 +69,20 @@ public class DeliveryReceiptRequest implements PacketExtension return packet.getExtension(ELEMENT, DeliveryReceipt.NAMESPACE); } + /** + * Add a delivery receipt request to an outgoing packet. + * + * Only message packets may contain receipt requests as of XEP-0184, + * therefore only allow Message as the parameter type. + * + * @param message Message object to add a request to + * @return the Message ID which will be used as receipt ID + */ + public static String addTo(Message message) { + message.addExtension(new DeliveryReceiptRequest()); + return message.getPacketID(); + } + /** * This Provider parses and returns DeliveryReceiptRequest packets. */ diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java index e08c504d9..cb7d6dd13 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java @@ -63,7 +63,7 @@ public class DeliveryReceiptTest extends InitExtensions { Message m = new Message("romeo@montague.com", Message.Type.normal); assertFalse(DeliveryReceiptManager.hasDeliveryReceiptRequest(m)); - DeliveryReceiptManager.addDeliveryReceiptRequest(m); + DeliveryReceiptRequest.addTo(m); assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(m)); } @@ -112,7 +112,7 @@ public class DeliveryReceiptTest extends InitExtensions { Message m = new Message("julia@capulet.com", Message.Type.normal); m.setFrom("romeo@montague.com"); m.setPacketID("test-receipt-request"); - DeliveryReceiptManager.addDeliveryReceiptRequest(m); + DeliveryReceiptRequest.addTo(m); // the DRM will send a reply-packet assertEquals(0, c.getNumberOfSentPackets());