1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

mam: support of advanced configuration

Fixes SMACK-822.

Co-authored-by: Jagmeet Singh <jagmeets@zeta.tech>
This commit is contained in:
Florian Schmaus 2020-04-09 15:15:27 +02:00
parent bf92712f4c
commit 353e43407f

View file

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.ConnectionCreationListener;
import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.SmackException.NotLoggedInException; import org.jivesoftware.smack.SmackException.NotLoggedInException;
import org.jivesoftware.smack.StanzaCollector; import org.jivesoftware.smack.StanzaCollector;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry; import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.IQReplyFilter; import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.packet.IQ; 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.packet.Stanza;
import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils; 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.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.forward.packet.Forwarded; 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;
import org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension; import org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension;
import org.jivesoftware.smackx.mam.element.MamFinIQ; import org.jivesoftware.smackx.mam.element.MamFinIQ;
@ -172,6 +175,8 @@ public final class MamManager extends Manager {
private static final Map<XMPPConnection, Map<Jid, MamManager>> INSTANCES = new WeakHashMap<>(); private static final Map<XMPPConnection, Map<Jid, MamManager>> 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. * 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 ServiceDiscoveryManager serviceDiscoveryManager;
private final AdHocCommandManager adHocCommandManager;
private MamManager(XMPPConnection connection, Jid archiveAddress) { private MamManager(XMPPConnection connection, Jid archiveAddress) {
super(connection); super(connection);
this.archiveAddress = archiveAddress; this.archiveAddress = archiveAddress;
serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
adHocCommandManager = AdHocCommandManager.getAddHocCommandsManager(connection);
} }
/** /**
@ -714,6 +722,25 @@ public final class MamManager extends Manager {
return serviceDiscoveryManager.supportsFeature(archiveAddress, MamElements.NAMESPACE); 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() { private static DataForm getNewMamForm() {
FormField field = FormField.hiddenFormType(MamElements.NAMESPACE); FormField field = FormField.hiddenFormType(MamElements.NAMESPACE);
DataForm form = new DataForm(DataForm.Type.submit); DataForm form = new DataForm(DataForm.Type.submit);