aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-11-28 15:09:02 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-11-28 15:09:02 +0100
commitbbe01c9a6afd2bf312c1ad38c482c53be743949c (patch)
treefa87b0c461ac906b84f0b4207203952822d8090e /src/main
parentfb6f0649c3a44de8a0102d8005654888fca2e96c (diff)
add support for body paramater in xmpp uri
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java10
-rw-r--r--src/main/java/eu/siacs/conversations/utils/XmppUri.java32
2 files changed, 36 insertions, 6 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index c674442f..25ce50eb 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -424,7 +424,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (invite != null && invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints());
}
- switchToConversation(contact);
+ switchToConversation(contact, invite == null ? null : invite.getBody());
return true;
}
}
@@ -563,11 +563,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
return xmppConnectionService.findAccountByJid(jid);
}
- protected void switchToConversation(Contact contact) {
+ protected void switchToConversation(Contact contact, String body) {
Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(),
contact.getJid(), false);
- switchToConversation(conversation);
+ switchToConversation(conversation, body, false);
}
public static void populateAccountSpinner(Context context, List<String> accounts, Spinner spinner) {
@@ -856,7 +856,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (invite.isMuc()) {
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
if (muc != null) {
- switchToConversation(muc);
+ switchToConversation(muc,invite.getBody(),false);
return true;
} else {
showJoinConferenceDialog(invite.getJid().toBareJid().toString());
@@ -870,7 +870,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints());
}
- switchToConversation(contact);
+ switchToConversation(contact,invite.getBody());
return true;
} else {
if (mMenuSearchView != null) {
diff --git a/src/main/java/eu/siacs/conversations/utils/XmppUri.java b/src/main/java/eu/siacs/conversations/utils/XmppUri.java
index 8cf5eeac..e16377cf 100644
--- a/src/main/java/eu/siacs/conversations/utils/XmppUri.java
+++ b/src/main/java/eu/siacs/conversations/utils/XmppUri.java
@@ -16,6 +16,7 @@ public class XmppUri {
protected String jid;
protected boolean muc;
protected List<Fingerprint> fingerprints = new ArrayList<>();
+ private String body;
public static final String OMEMO_URI_PARAM = "omemo-sid-";
public static final String OTR_URI_PARAM = "otr-fingerprint";
@@ -55,13 +56,14 @@ public class XmppUri {
muc = segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0));
} else if ("xmpp".equalsIgnoreCase(scheme)) {
// sample: xmpp:foo@bar.com
- muc = "join".equalsIgnoreCase(uri.getQuery());
+ muc = isMuc(uri.getQuery());
if (uri.getAuthority() != null) {
jid = uri.getAuthority();
} else {
jid = uri.getSchemeSpecificPart().split("\\?")[0];
}
this.fingerprints = parseFingerprints(uri.getQuery());
+ this.body = parseBody(uri.getQuery());
} else if ("imto".equalsIgnoreCase(scheme)) {
// sample: imto://xmpp/foo@bar.com
try {
@@ -102,6 +104,30 @@ public class XmppUri {
return fingerprints;
}
+ protected String parseBody(String query) {
+ for(String pair : query == null ? new String[0] : query.split(";")) {
+ final String[] parts = pair.split("=",2);
+ if (parts.length == 2 && "body".equals(parts[0].toLowerCase(Locale.US))) {
+ try {
+ return URLDecoder.decode(parts[1],"UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ return null;
+ }
+ }
+ }
+ return null;
+ }
+
+ protected boolean isMuc(String query) {
+ for(String pair : query == null ? new String[0] : query.split(";")) {
+ final String[] parts = pair.split("=",2);
+ if (parts.length == 1 && "join".equals(parts[0])) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public Jid getJid() {
try {
return this.jid == null ? null :Jid.fromString(this.jid.toLowerCase());
@@ -110,6 +136,10 @@ public class XmppUri {
}
}
+ public String getBody() {
+ return body;
+ }
+
public List<Fingerprint> getFingerprints() {
return this.fingerprints;
}