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 0000000000..e8ef1af5e1
--- /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 0000000000..b05f10df0d
--- /dev/null
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/DirectMucInvitationManager.java
@@ -0,0 +1,111 @@
+/**
+ *
+ * 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 { @@ -68,6 +51,12 @@ public class GroupChatInvitation implements ExtensionElement { public static final QName QNAME = new QName(NAMESPACE, ELEMENT); + 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 reason; private final String password; @@ -170,18 +159,37 @@ public String getNamespace() { @Override public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { XmlStringBuilder xml = new XmlStringBuilder(this); - xml.attribute("jid", getRoomAddress()); - xml.optAttribute("reason", getReason()); - xml.optAttribute("password", getPassword()); - xml.optAttribute("thread", getThread()); - - if (continueAsOneToOneChat()) - xml.optBooleanAttribute("continue", true); + xml.jidAttribute(getRoomAddress()); + xml.optAttribute(ATTR_REASON, getReason()); + xml.optAttribute(ATTR_PASSWORD, getPassword()); + xml.optAttribute(ATTR_THREAD, getThread()); + xml.optBooleanAttribute(ATTR_CONTINUE, continueAsOneToOneChat()); xml.closeEmptyElement(); return xml; } + @Override + public boolean equals(Object obj) { + return EqualsUtil.equals(this, obj, (equalsBuilder, other) -> equalsBuilder + .append(getRoomAddress(), other.getRoomAddress()) + .append(getPassword(), other.getPassword()) + .append(getReason(), other.getReason()) + .append(continueAsOneToOneChat(), other.continueAsOneToOneChat()) + .append(getThread(), other.getThread())); + } + + @Override + public int hashCode() { + return HashCode.builder() + .append(getRoomAddress()) + .append(getPassword()) + .append(getReason()) + .append(continueAsOneToOneChat()) + .append(getThread()) + .build(); + } + /** * Get the group chat invitation from the given stanza. * @param packet TODO javadoc me please diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/GroupChatInvitationProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/GroupChatInvitationProvider.java index 31f6472c88..00ddabaf9c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/GroupChatInvitationProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/GroupChatInvitationProvider.java @@ -1,6 +1,6 @@ /** * - * Copyright 2003-2007 Jive Software, 2022 Florian Schmaus. + * Copyright 2003-2007 Jive Software, 2020 Paul Schaub, 2022-2023 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,12 @@ */ package org.jivesoftware.smackx.muc.provider; +import static org.jivesoftware.smackx.muc.packet.GroupChatInvitation.ATTR_CONTINUE; +import static org.jivesoftware.smackx.muc.packet.GroupChatInvitation.ATTR_PASSWORD; +import static org.jivesoftware.smackx.muc.packet.GroupChatInvitation.ATTR_REASON; +import static org.jivesoftware.smackx.muc.packet.GroupChatInvitation.ATTR_THREAD; + import java.io.IOException; -import java.text.ParseException; import org.jivesoftware.smack.packet.XmlEnvironment; import org.jivesoftware.smack.parsing.SmackParsingException; @@ -33,11 +37,14 @@ public class GroupChatInvitationProvider extends ExtensionElementProvider