From 0fac4be94da6c0822bdc48477931e6225168ef6b Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Tue, 5 Dec 2017 21:46:48 +0100 Subject: [PATCH] XmppUri: Parse 'message action' query --- .../ui/StartConversationActivity.java | 6 +--- .../eu/siacs/conversations/utils/XmppUri.java | 31 ++++++++++++++++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 914ed6358..ecc7a891d 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -876,7 +876,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU return true; } List contacts = xmppConnectionService.findContacts(invite.getJid(),invite.account); - if (invite.isMuc()) { + if (invite.isAction(XmppUri.ACTION_JOIN)) { Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid()); if (muc != null) { switchToConversation(muc,invite.getBody(),false); @@ -1202,9 +1202,5 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } return false; } - - public boolean isMuc() { - return muc; - } } } diff --git a/src/main/java/eu/siacs/conversations/utils/XmppUri.java b/src/main/java/eu/siacs/conversations/utils/XmppUri.java index c20c9a4ac..ec8fd51c0 100644 --- a/src/main/java/eu/siacs/conversations/utils/XmppUri.java +++ b/src/main/java/eu/siacs/conversations/utils/XmppUri.java @@ -14,14 +14,17 @@ import eu.siacs.conversations.xmpp.jid.Jid; public class XmppUri { protected String jid; - protected boolean muc; protected List fingerprints = new ArrayList<>(); private String body; + private String action; protected boolean safeSource = true; public static final String OMEMO_URI_PARAM = "omemo-sid-"; public static final String OTR_URI_PARAM = "otr-fingerprint"; + public static final String ACTION_JOIN = "join"; + public static final String ACTION_MESSAGE = "message"; + public XmppUri(String uri) { try { parse(Uri.parse(uri)); @@ -63,11 +66,21 @@ public class XmppUri { // sample : https://conversations.im/i/foo/bar.com jid = segments.get(1) + "@" + segments.get(2); } - muc = segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0)); + if (segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0))) { + action = ACTION_JOIN; + } fingerprints = parseFingerprints(uri.getQuery(),'&'); } else if ("xmpp".equalsIgnoreCase(scheme)) { // sample: xmpp:foo@bar.com - muc = isMuc(uri.getQuery()); + + final String query = uri.getQuery(); + + if (hasAction(query, ACTION_JOIN)) { + this.action = ACTION_JOIN; + } else if (hasAction(query, ACTION_MESSAGE)) { + this.action = ACTION_MESSAGE; + } + if (uri.getAuthority() != null) { jid = uri.getAuthority(); } else { @@ -138,16 +151,24 @@ public class XmppUri { return null; } - protected boolean isMuc(String query) { + private boolean hasAction(String query, String action) { for(String pair : query == null ? new String[0] : query.split(";")) { final String[] parts = pair.split("=",2); - if (parts.length == 1 && "join".equals(parts[0])) { + if (parts.length == 1 && parts[0].equals(action)) { return true; } } return false; } + public boolean isAction(final String action) { + if (this.action == null) { + return false; + } + + return this.action.equals(action); + } + public Jid getJid() { try { return this.jid == null ? null :Jid.fromString(this.jid.toLowerCase());