aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-01-15 21:09:22 +0100
committerChristian Schneppe <christian@pix-art.de>2019-02-08 14:09:53 +0100
commit05476102032e921b76db1ad9805b238d0355e94a (patch)
tree8426dcca441cd15cddaa9af6091b89df5317a9b6 /src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
parent141a37a7c8691828ba1d2e028998897e2467f868 (diff)
implement adhoc invite links if server supports this
Diffstat (limited to 'src/main/java/de/pixart/messenger/xmpp/XmppConnection.java')
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index f364a0155..5e3205684 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -1297,6 +1297,7 @@ public class XmppConnection implements Runnable {
for (Jid jid : items) {
sendServiceDiscoveryInfo(jid);
}
+ getInviteAdHoc(server);
} else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not query disco items of " + server);
}
@@ -1309,6 +1310,76 @@ public class XmppConnection implements Runnable {
});
}
+ private void getInviteAdHoc(final Jid server) {
+ mPendingServiceDiscoveries.incrementAndGet();
+ ArrayList<String> nodes = new ArrayList<String>();
+ IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
+ iq.setTo(Jid.ofDomain(server.getDomain()));
+ iq.setFrom(Jid.of(account.getJid().asBareJid()));
+ iq.setAttribute("query", "jabber:client");
+ final Element query = iq.addChild("query", "http://jabber.org/protocol/disco#items");
+ query.setAttribute("node", "http://jabber.org/protocol/commands");
+ this.sendIqPacket(iq, (account, packet) -> {
+ if (packet.getType() == IqPacket.TYPE.RESULT) {
+ final List<Element> elements = packet.query().getChildren();
+ for (final Element element : elements) {
+ if (element.getName().equals("item")) {
+ final Jid jid = InvalidJid.getNullForInvalid(element.getAttributeAsJid("jid"));
+ if (jid != null && jid.equals(Jid.of(account.getServer()))) {
+ final String node = element.getAttribute("node");
+ if (node.equals("invite")) {
+ features.adhocinvite = true;
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": query disco commands of " + server + " was successful");
+ getAdHocInviteUrl(server);
+ }
+ nodes.add(node);
+ }
+ }
+ }
+ } else {
+ features.adhocinvite = false;
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not query disco commands of " + server);
+ }
+ if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
+ if (mPendingServiceDiscoveries.decrementAndGet() == 0
+ && mWaitForDisco.compareAndSet(true, false)) {
+ finalizeBind();
+ }
+ }
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": query disco commands of " + server + " was " + features.adhocinvite);
+ });
+ }
+
+ private void getAdHocInviteUrl(final Jid server) {
+ IqPacket iqPacket = new IqPacket(IqPacket.TYPE.SET);
+ iqPacket.setTo(Jid.ofDomain(server.getDomain()));
+ iqPacket.setFrom(Jid.of(account.getJid().asBareJid()));
+ iqPacket.setContent("jabber:client");
+ final Element command = iqPacket.addChild("command", "http://jabber.org/protocol/commands");
+ command.setAttribute("node", "invite");
+ command.setAttribute("action", "execute");
+ Log.d(Config.LOGTAG, "AdHoc URL command " + iqPacket);
+ this.sendIqPacket(iqPacket, (account, packet) -> {
+ Log.d(Config.LOGTAG, "AdHoc URL packet " + packet);
+ if (packet.getType() == IqPacket.TYPE.RESULT) {
+ final List<Element> elements = packet.command().getChildren();
+ for (final Element element : elements) {
+ features.adhocinviteURI = element.getContent();
+ Log.d(Config.LOGTAG, "Commands URI: " + features.adhocinviteURI);
+ }
+ } else {
+ features.adhocinviteURI = "";
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not query disco commands of " + server);
+ }
+ if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
+ if (mPendingServiceDiscoveries.decrementAndGet() == 0
+ && mWaitForDisco.compareAndSet(true, false)) {
+ finalizeBind();
+ }
+ }
+ });
+ }
+
private void sendEnableCarbons() {
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
iq.addChild("enable", "urn:xmpp:carbons:2");
@@ -1756,6 +1827,8 @@ public class XmppConnection implements Runnable {
}
public class Features {
+ public boolean adhocinvite;
+ public String adhocinviteURI;
XmppConnection connection;
private boolean carbonsEnabled = false;
private boolean encryptionEnabled = false;