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()) { if (invite != null && invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints()); xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints());
} }
switchToConversation(contact); switchToConversation(contact, invite == null ? null : invite.getBody());
return true; return true;
} }
} }
@ -563,11 +563,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
return xmppConnectionService.findAccountByJid(jid); return xmppConnectionService.findAccountByJid(jid);
} }
protected void switchToConversation(Contact contact) { protected void switchToConversation(Contact contact, String body) {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(), .findOrCreateConversation(contact.getAccount(),
contact.getJid(), false); contact.getJid(), false);
switchToConversation(conversation); switchToConversation(conversation, body, false);
} }
public static void populateAccountSpinner(Context context, List<String> accounts, Spinner spinner) { 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()) { if (invite.isMuc()) {
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid()); Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
if (muc != null) { if (muc != null) {
switchToConversation(muc); switchToConversation(muc,invite.getBody(),false);
return true; return true;
} else { } else {
showJoinConferenceDialog(invite.getJid().toBareJid().toString()); showJoinConferenceDialog(invite.getJid().toBareJid().toString());
@ -870,7 +870,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (invite.hasFingerprints()) { if (invite.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints()); xmppConnectionService.verifyFingerprints(contact,invite.getFingerprints());
} }
switchToConversation(contact); switchToConversation(contact,invite.getBody());
return true; return true;
} else { } else {
if (mMenuSearchView != null) { if (mMenuSearchView != null) {

View file

@ -16,6 +16,7 @@ public class XmppUri {
protected String jid; protected String jid;
protected boolean muc; protected boolean muc;
protected List<Fingerprint> fingerprints = new ArrayList<>(); protected List<Fingerprint> fingerprints = new ArrayList<>();
private String body;
public static final String OMEMO_URI_PARAM = "omemo-sid-"; public static final String OMEMO_URI_PARAM = "omemo-sid-";
public static final String OTR_URI_PARAM = "otr-fingerprint"; 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)); muc = segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0));
} else if ("xmpp".equalsIgnoreCase(scheme)) { } else if ("xmpp".equalsIgnoreCase(scheme)) {
// sample: xmpp:foo@bar.com // sample: xmpp:foo@bar.com
muc = "join".equalsIgnoreCase(uri.getQuery()); muc = isMuc(uri.getQuery());
if (uri.getAuthority() != null) { if (uri.getAuthority() != null) {
jid = uri.getAuthority(); jid = uri.getAuthority();
} else { } else {
jid = uri.getSchemeSpecificPart().split("\\?")[0]; jid = uri.getSchemeSpecificPart().split("\\?")[0];
} }
this.fingerprints = parseFingerprints(uri.getQuery()); this.fingerprints = parseFingerprints(uri.getQuery());
this.body = parseBody(uri.getQuery());
} else if ("imto".equalsIgnoreCase(scheme)) { } else if ("imto".equalsIgnoreCase(scheme)) {
// sample: imto://xmpp/foo@bar.com // sample: imto://xmpp/foo@bar.com
try { try {
@ -102,6 +104,30 @@ public class XmppUri {
return fingerprints; 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() { public Jid getJid() {
try { try {
return this.jid == null ? null :Jid.fromString(this.jid.toLowerCase()); 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() { public List<Fingerprint> getFingerprints() {
return this.fingerprints; return this.fingerprints;
} }