aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <xmpp-dev@marcschink.de>2018-09-15 14:15:31 +0200
committerMarc Schink <xmpp-dev@marcschink.de>2018-10-03 22:47:26 +0200
commit8443378f35408923f8d888c13531942b3a3fe1f2 (patch)
treea35b8c38de3111ee00cc13d2ae11860a8699a575
parentadb181974b39197b24b7b59be5b4122a6a532d0c (diff)
TODO/FIXUP: XmppConnectionService: generateInvitation()easy_user_onboarding_new
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 3886b56..258207d 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -50,6 +50,7 @@ import java.security.SecureRandom;
import java.security.Security;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
+import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -142,6 +143,7 @@ import eu.siacs.conversations.xmpp.Patches;
import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.forms.Data;
+import eu.siacs.conversations.xmpp.forms.Field;
import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager;
import eu.siacs.conversations.xmpp.jingle.OnJinglePacketReceived;
import eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket;
@@ -1461,6 +1463,84 @@ public class XmppConnectionService extends Service {
});
}
+ public void generateInvitation(Account account, final OnContactInvited callback) {
+ final IqPacket iqPacket = new IqPacket(IqPacket.TYPE.SET);
+ iqPacket.setTo(Jid.of(account.getServer()));
+ final Element command = iqPacket.addChild("command", Namespace.ADHOC_COMMANDS);
+ command.setAttribute("node","invite");
+ command.setAttribute("action","execute");
+
+ Log.d(Config.LOGTAG, "foobar: " + iqPacket);
+
+ final OnIqPacketReceived iqCallback = new OnIqPacketReceived() {
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ if (packet.getType() == IqPacket.TYPE.ERROR) {
+ Log.d(Config.LOGTAG, "XmppConnectionService: invite failed: " + packet.toString());
+ callback.onError();
+ return;
+ }
+
+ Log.d(Config.LOGTAG, "callback: " + packet);
+
+ Log.d(Config.LOGTAG, "Invite command successful!");
+
+ final Element command = packet.findChild("command", Namespace.ADHOC_COMMANDS);
+
+ if (command == null) {
+ Log.d(Config.LOGTAG, "Invalid response, no 'command' element");
+ return;
+ }
+
+ final Element x = command.findChild("x", Namespace.DATA);
+
+ if (x == null) {
+ Log.d(Config.LOGTAG, "Invalid repsonse, no 'x' element");
+ return;
+ }
+
+ final Data data = Data.parse(x);
+ final Field uriField = data.getFieldByName("uri");
+
+ if (uriField == null) {
+ Log.d(Config.LOGTAG, "Invalid repose, URI field is missing");
+ return;
+ }
+
+ final XmppUri xmppUri = new XmppUri(uriField.getValue());
+
+ if (xmppUri == null) {
+ Log.d(Config.LOGTAG, "Invalid XMPP URI");
+ return;
+ }
+
+ final Field expireField = data.getFieldByName("expire");
+ Date expire = null;
+
+ if (expireField != null) {
+ try {
+ long tmp = AbstractParser.parseTimestamp(expireField.getValue());
+ expire = new Date(tmp);
+ } catch (ParseException e) {
+ Log.d(Config.LOGTAG, "Invalid response, invalid expire date");
+ return;
+ }
+ }
+
+ final Field landingUrlField = data.getFieldByName("landing-url");
+ String landingUrl = null;
+
+ if (landingUrlField != null) {
+ landingUrl = landingUrlField.getValue();
+ }
+
+ callback.onSuccess(xmppUri, landingUrl, expire);
+ }
+ };
+
+ sendIqPacket(account, iqPacket, iqCallback);
+ }
+
private void restoreFromDatabase() {
synchronized (this.conversations) {
final Map<String, Account> accountLookupTable = new Hashtable<>();