aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-02-08 14:17:33 +0100
committerChristian Schneppe <christian@pix-art.de>2019-02-08 14:28:27 +0100
commit2e92fe8044127712ef790320c27783feaf9f1aa7 (patch)
tree98e69288e798f1a131e39522e3cd74078b8439e0 /src/main/java
parentec08e6dd6200f3544a9681ab6463b0f90624cf01 (diff)
parent05476102032e921b76db1ad9805b238d0355e94a (diff)
use ad-hoc commands for invite links if server supports this
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java5
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java12
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java69
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/stanzas/IqPacket.java8
4 files changed, 94 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index 117a33315..bec621534 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -1114,6 +1114,11 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} else {
this.binding.serverInfoSm.setText(R.string.server_info_unavailable);
}
+ if (features.adhocinvite) {
+ this.binding.serverInfoAdhocInvite.setText(R.string.server_info_available);
+ } else {
+ this.binding.serverInfoAdhocInvite.setText(R.string.server_info_unavailable);
+ }
if (features.pep()) {
AxolotlService axolotlService = this.mAccount.getAxolotlService();
if (axolotlService != null && axolotlService.isPepBroken()) {
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index d269f11ac..b64b4ae71 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -90,6 +90,7 @@ import de.pixart.messenger.utils.MenuDoubleTabUtil;
import de.pixart.messenger.utils.ThemeHelper;
import de.pixart.messenger.xmpp.OnKeyStatusUpdated;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
+import de.pixart.messenger.xmpp.XmppConnection;
import pl.droidsonroids.gif.GifDrawable;
import rocks.xmpp.addr.Jid;
@@ -964,6 +965,11 @@ public abstract class XmppActivity extends ActionBarActivity {
String user = Jid.of(mAccount.getJid()).getLocal();
String domain = Jid.of(mAccount.getJid()).getDomain();
String inviteURL = Config.inviteUserURL + user + "/" + domain;
+ XmppConnection.Features features = mAccount.getXmppConnection().getFeatures();
+ final boolean adhoclink = features.adhocinvite;
+ if (adhoclink) {
+ inviteURL = features.adhocinviteURI;
+ }
String inviteText = getString(R.string.InviteText, user);
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
@@ -991,9 +997,15 @@ public abstract class XmppActivity extends ActionBarActivity {
builder.setPositiveButton(R.string.ok,
(dialog, id) -> {
String selection = spinner.getSelectedItem().toString();
+ Account mAccount = xmppConnectionService.findAccountByJid(Jid.of(selection).asBareJid());
String user = Jid.of(selection).getLocal();
String domain = Jid.of(selection).getDomain();
String inviteURL = Config.inviteUserURL + user + "/" + domain;
+ XmppConnection.Features features = mAccount.getXmppConnection().getFeatures();
+ final boolean adhoclink = features.adhocinvite;
+ if (adhoclink) {
+ inviteURL = features.adhocinviteURI;
+ }
String inviteText = getString(R.string.InviteText, user);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index 2c736493e..0eb5a5dcb 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -1296,6 +1296,7 @@ public class XmppConnection implements Runnable {
for (Jid jid : items) {
sendServiceDiscoveryInfo(jid);
}
+ getAdHocFeatures(server);
} else {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not query disco items of " + server);
}
@@ -1308,6 +1309,72 @@ public class XmppConnection implements Runnable {
});
}
+ private void getAdHocFeatures(final Jid server) {
+ mPendingServiceDiscoveries.incrementAndGet();
+ 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);
+ }
+ }
+ }
+ }
+ } else {
+ 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 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");
@@ -1755,6 +1822,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;
diff --git a/src/main/java/de/pixart/messenger/xmpp/stanzas/IqPacket.java b/src/main/java/de/pixart/messenger/xmpp/stanzas/IqPacket.java
index 5f4e39eca..c74ec3237 100644
--- a/src/main/java/de/pixart/messenger/xmpp/stanzas/IqPacket.java
+++ b/src/main/java/de/pixart/messenger/xmpp/stanzas/IqPacket.java
@@ -32,6 +32,14 @@ public class IqPacket extends AbstractAcknowledgeableStanza {
return query;
}
+ public Element command() {
+ Element command = findChild("command");
+ if (command == null) {
+ command = addChild("command");
+ }
+ return command;
+ }
+
public Element query(final String xmlns) {
final Element query = query();
query.setAttribute("xmlns", xmlns);