diff --git a/documentation/extensions/index.md b/documentation/extensions/index.md
index 78a2bbc57..f26793168 100644
--- a/documentation/extensions/index.md
+++ b/documentation/extensions/index.md
@@ -84,12 +84,12 @@ Smack Extensions and currently supported XEPs of smack-extensions
| Attention | [XEP-0224](https://xmpp.org/extensions/xep-0224.html) | n/a | Getting attention of another user. |
| Bits of Binary | [XEP-0231](https://xmpp.org/extensions/xep-0231.html) | n/a | Including or referring to small bits of binary data in an XML stanza. |
| Software Information | [XEP-0232](https://xmpp.org/extensions/xep-0232.html) | 0.3 | Allows an entity to provide detailed data about itself in Service Discovery responses. |
+| Direct MUC Invitations | [XEP-0249](https://xmpp.org/extensions/xep-0249.html) | 1.2 | Invite other users to group chats. |
| Best Practices for Resource Locking | [XEP-0296](https://xmpp.org/extensions/xep-0296.html) | n/a | Specifies best practices to be followed by Jabber/XMPP clients about when to lock into, and unlock away from, resources. |
| Stanza Forwarding | [XEP-0297](https://xmpp.org/extensions/xep-0297.html) | n/a | Allows forwarding of Stanzas. |
| Last Message Correction | [XEP-0308](https://xmpp.org/extensions/xep-0308.html) | n/a | Provides a method for indicating that a message is a correction of the last sent message. |
| Last User Interaction in Presence | [XEP-0319](https://xmpp.org/extensions/xep-0319.html) | n/a | Communicate time of last user interaction via XMPP presence notifications. |
| Data Forms Geolocation Element | [XEP-0350](https://xmpp.org/extensions/xep-0350.html) | n/a | Allows to include XEP-0080 gelocation data in XEP-0004 data forms. |
-| [Group Chat Invitations](invitation.md) | n/a | n/a | Send invitations to other users to join a group chat room. |
| [Jive Properties](properties.md) | n/a | n/a | TODO |
diff --git a/documentation/extensions/invitation.md b/documentation/extensions/invitation.md
index f940bb06f..f2ee1d529 100644
--- a/documentation/extensions/invitation.md
+++ b/documentation/extensions/invitation.md
@@ -10,6 +10,7 @@ group chat room.
* Listen for Invitations
**XEP related:** N/A -- this protocol is outdated now that the Multi-User Chat (MUC) XEP is available ([XEP-45](http://www.xmpp.org/extensions/xep-0045.html)). However, most existing clients still use this older protocol. Once MUC support becomes more widespread, this API may be deprecated.
+**XEP related:** Now there is support for XEP-0249: Direct MUC Invitations.
Inviting Other Users
--------------------
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationListener.java
new file mode 100644
index 000000000..e8ef1af5e
--- /dev/null
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationListener.java
@@ -0,0 +1,25 @@
+/**
+ *
+ * Copyright 2020 Paul Schaub.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jivesoftware.smackx.muc;
+
+import org.jivesoftware.smack.packet.Stanza;
+import org.jivesoftware.smackx.muc.packet.GroupChatInvitation;
+
+public interface DirectMucInvitationListener {
+
+ void invitationReceived(GroupChatInvitation invitation, Stanza stanza);
+}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationManager.java
new file mode 100644
index 000000000..24156a924
--- /dev/null
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationManager.java
@@ -0,0 +1,115 @@
+/**
+ *
+ * Copyright 2020 Paul Schaub.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jivesoftware.smackx.muc;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jivesoftware.smack.Manager;
+import org.jivesoftware.smack.SmackException;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPConnectionRegistry;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.filter.StanzaExtensionFilter;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.MessageBuilder;
+import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
+import org.jivesoftware.smackx.muc.packet.GroupChatInvitation;
+
+import org.jxmpp.jid.EntityBareJid;
+
+/**
+ * Smacks API for XEP-0249: Direct MUC Invitations.
+ * Use this instead of {@link org.jivesoftware.smackx.muc.packet.MUCUser.Invite}.
+ *
+ * To invite a user to a group chat, use {@link #inviteToMuc(MultiUserChat, EntityBareJid)}.
+ *
+ * In order to listen for incoming invitations, register a {@link DirectMucInvitationListener} using
+ * {@link #addInvitationListener(DirectMucInvitationListener)}.
+ *
+ * @see Direct MUC Invitations
+ */
+public final class DirectMucInvitationManager extends Manager {
+
+ private static final Map
- * Message message = new Message("user@chat.example.com"); - * message.setBody("Join me for a group chat!"); - * message.addExtension(new GroupChatInvitation("room@chat.example.com");); - * con.sendStanza(message); - *- * - * To listen for group chat invitations, use a StanzaExtensionFilter for the - *
x
element name and jabber:x:conference
namespace, as in the
- * following code example:
- *
- * - * PacketFilter filter = new StanzaExtensionFilter("x", "jabber:x:conference"); - * // Create a stanza collector or stanza listeners using the filter... - *- * - * Note: this protocol is outdated now that the Multi-User Chat (MUC) XEP is available - * (XEP-45). However, most - * existing clients still use this older protocol. Once MUC support becomes more - * widespread, this API may be deprecated. + * This implementation now conforms to XEP-0249: Direct MUC Invitations, + * while staying backwards compatible to legacy MUC invitations. * * @author Matt Tucker + * @author Paul Schaub */ public class GroupChatInvitation implements ExtensionElement { @@ -69,10 +51,19 @@ public class GroupChatInvitation implements ExtensionElement { * Namespace of the stanza extension. */ public static final String NAMESPACE = "jabber:x:conference"; - public static final QName QNAME = new QName(NAMESPACE, ELEMENT); - private final String roomAddress; + public static final String ATTR_CONTINUE = "continue"; + public static final String ATTR_JID = "jid"; + public static final String ATTR_PASSWORD = "password"; + public static final String ATTR_REASON = "reason"; + public static final String ATTR_THREAD = "thread"; + + private final EntityBareJid roomAddress; + private final String password; + private final String reason; + private final boolean _continue; + private final String thread; /** * Creates a new group chat invitation to the specified room address. @@ -81,9 +72,23 @@ public class GroupChatInvitation implements ExtensionElement { *
chat.example.com
.
*
* @param roomAddress the address of the group chat room.
+ * @deprecated use {@link #GroupChatInvitation(EntityBareJid)} instead.
*/
+ @Deprecated
public GroupChatInvitation(String roomAddress) {
- this.roomAddress = roomAddress;
+ this(JidCreate.entityBareFromOrThrowUnchecked(roomAddress));
+ }
+
+ public GroupChatInvitation(EntityBareJid roomAddress) {
+ this(roomAddress, null, null, false, null);
+ }
+
+ public GroupChatInvitation(EntityBareJid mucJid, String password, String reason, boolean _continue, String thread) {
+ this.roomAddress = Objects.requireNonNull(mucJid);
+ this.password = password;
+ this.reason = reason;
+ this._continue = _continue;
+ this.thread = thread;
}
/**
@@ -91,12 +96,62 @@ public class GroupChatInvitation implements ExtensionElement {
* are in the form room@service
, where service
is
* the name of group chat server, such as chat.example.com
.
*
+ * TODO: Remove in Smack 4.5
+ * @deprecated use {@link #getRoomAddressJid()} instead.
* @return the address of the group chat room.
*/
+ @Deprecated
public String getRoomAddress() {
+ return roomAddress.asEntityBareJidString();
+ }
+
+ /**
+ * Returns the address of the group chat room as an {@link EntityBareJid}.
+ *
+ * @return room address
+ */
+ public EntityBareJid getRoomAddressJid() {
return roomAddress;
}
+ /**
+ * Returns the password which is used to join the room.
+ * This value can be null if no password is required.
+ *
+ * @return password
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * Return the reason of invitation.
+ *
+ * @return reason
+ */
+ public String getReason() {
+ return reason;
+ }
+
+ /**
+ * Returns true if the invitation represents the continuation of a one-to-one chat.
+ * The chat continues the thread returned by {@link #getThread()}.
+ *
+ * @return true if this is a continued one-to-one chat, false otherwise.
+ */
+ public boolean isContinue() {
+ return _continue;
+ }
+
+ /**
+ * In case of a continuation, this returns the thread name of the one-to-one chat that is being continued.
+ *
+ * @return thread
+ */
+ public String getThread() {
+ return thread;
+ }
+
@Override
public String getElementName() {
return ELEMENT;
@@ -108,11 +163,35 @@ public class GroupChatInvitation implements ExtensionElement {
}
@Override
- public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
- XmlStringBuilder xml = new XmlStringBuilder(this);
- xml.attribute("jid", getRoomAddress());
- xml.closeEmptyElement();
- return xml;
+ public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
+ return new XmlStringBuilder(this)
+ .optBooleanAttribute(ATTR_CONTINUE, isContinue())
+ .attribute(ATTR_JID, getRoomAddressJid())
+ .optAttribute(ATTR_PASSWORD, getPassword())
+ .optAttribute(ATTR_REASON, getReason())
+ .optAttribute(ATTR_THREAD, getThread())
+ .closeEmptyElement();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return EqualsUtil.equals(this, obj, (equalsBuilder, other) -> equalsBuilder
+ .append(getRoomAddressJid(), other.getRoomAddressJid())
+ .append(getPassword(), other.getPassword())
+ .append(getReason(), other.getReason())
+ .append(isContinue(), other.isContinue())
+ .append(getThread(), other.getThread()));
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCode.builder()
+ .append(getRoomAddressJid())
+ .append(getPassword())
+ .append(getReason())
+ .append(isContinue())
+ .append(getThread())
+ .build();
}
/**
@@ -123,17 +202,4 @@ public class GroupChatInvitation implements ExtensionElement {
public static GroupChatInvitation from(Stanza packet) {
return packet.getExtension(GroupChatInvitation.class);
}
-
- public static class Provider extends ExtensionElementProvider