From 5a2326a85655eab627dc1069d698b3071b3d64f5 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 31 Oct 2016 12:24:03 +0100 Subject: [PATCH] Add convinient constructors for Message and Presence --- .../java/org/jivesoftware/smack/packet/Message.java | 12 ++++++++++++ .../org/jivesoftware/smack/packet/Presence.java | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java index 2a6321e1e..6751e89a3 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java @@ -114,6 +114,18 @@ public final class Message extends Stanza implements TypedCloneable { this(JidCreate.from(to), body); } + /** + * Creates a new message with the specified recipient and extension element. + * + * @param to + * @param extensionElement + * @since 4.2 + */ + public Message(Jid to, ExtensionElement extensionElement) { + this(to); + addExtension(extensionElement); + } + /** * Copy constructor. *

diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java index cd9aedf77..976c60dd6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java @@ -24,6 +24,7 @@ import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.TypedCloneable; import org.jivesoftware.smack.util.XmlStringBuilder; +import org.jxmpp.jid.Jid; /** * Represents XMPP presence packets. Every presence stanza(/packet) has a type, which is one of @@ -78,6 +79,18 @@ public final class Presence extends Stanza implements TypedCloneable { setType(type); } + /** + * Creates a new presence with the given type and using the given XMPP address as recipient. + * + * @param to the recipient. + * @param type the type. + * @since 4.2 + */ + public Presence(Jid to, Type type) { + this(type); + setTo(to); + } + /** * Creates a new presence update with a specified status, priority, and mode. *