add support for body paramater in xmpp uri

This commit is contained in:
Daniel Gultsch 2016-11-28 15:09:02 +01:00
parent fb6f0649c3
commit bbe01c9a6a
2 changed files with 36 additions and 6 deletions

View file

@ -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) {

View file

@ -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;
}