From 353e43407f8ccc4b610ea187793472b58a49da3a Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 9 Apr 2020 15:15:27 +0200 Subject: [PATCH] mam: support of advanced configuration Fixes SMACK-822. Co-authored-by: Jagmeet Singh --- .../jivesoftware/smackx/mam/MamManager.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java index e95048665..3b7b3ef75 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/mam/MamManager.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2017-2019 Florian Schmaus, 2016-2017 Fernando Ramirez + * Copyright © 2017-2020 Florian Schmaus, 2016-2017 Fernando Ramirez * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,12 +28,14 @@ import java.util.WeakHashMap; import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.Manager; +import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotLoggedInException; import org.jivesoftware.smack.StanzaCollector; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnectionRegistry; +import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.filter.IQReplyFilter; import org.jivesoftware.smack.packet.IQ; @@ -41,10 +43,11 @@ import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.StringUtils; - +import org.jivesoftware.smackx.commands.AdHocCommandManager; +import org.jivesoftware.smackx.commands.RemoteCommand; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; +import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.forward.packet.Forwarded; -import org.jivesoftware.smackx.mam.MamManager.MamQueryArgs; import org.jivesoftware.smackx.mam.element.MamElements; import org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension; import org.jivesoftware.smackx.mam.element.MamFinIQ; @@ -172,6 +175,8 @@ public final class MamManager extends Manager { private static final Map> INSTANCES = new WeakHashMap<>(); + private static final String ADVANCED_CONFIG_NODE = "urn:xmpp:mam#configure"; + /** * Get a MamManager for the MAM archive of the local entity (the "user") of the given connection. * @@ -216,10 +221,13 @@ public final class MamManager extends Manager { private final ServiceDiscoveryManager serviceDiscoveryManager; + private final AdHocCommandManager adHocCommandManager; + private MamManager(XMPPConnection connection, Jid archiveAddress) { super(connection); this.archiveAddress = archiveAddress; serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); + adHocCommandManager = AdHocCommandManager.getAddHocCommandsManager(connection); } /** @@ -714,6 +722,25 @@ public final class MamManager extends Manager { return serviceDiscoveryManager.supportsFeature(archiveAddress, MamElements.NAMESPACE); } + public boolean isAdvancedConfigurationSupported() throws InterruptedException, XMPPException, SmackException { + DiscoverItems discoverItems = adHocCommandManager.discoverCommands(archiveAddress); + for (DiscoverItems.Item item : discoverItems.getItems()) { + if (item.getNode().equals(ADVANCED_CONFIG_NODE)) { + return true; + } + } + return false; + } + + public RemoteCommand getAdvancedConfigurationCommand() throws InterruptedException, XMPPException, SmackException { + DiscoverItems discoverItems = adHocCommandManager.discoverCommands(archiveAddress); + for (DiscoverItems.Item item : discoverItems.getItems()) { + if (item.getNode().equals(ADVANCED_CONFIG_NODE)) + return adHocCommandManager.getRemoteCommand(archiveAddress, item.getNode()); + } + throw new SmackException.FeatureNotSupportedException(ADVANCED_CONFIG_NODE, archiveAddress); + } + private static DataForm getNewMamForm() { FormField field = FormField.hiddenFormType(MamElements.NAMESPACE); DataForm form = new DataForm(DataForm.Type.submit);