add omemo fingerprints to web links as well

This commit is contained in:
Daniel Gultsch 2016-12-03 13:37:26 +01:00
parent 6e289b8738
commit 56991bbaeb
3 changed files with 33 additions and 18 deletions

View file

@ -610,23 +610,17 @@ public class Account extends AbstractEntity {
List<XmppUri.Fingerprint> fingerprints = this.getFingerprints(); List<XmppUri.Fingerprint> fingerprints = this.getFingerprints();
String uri = "xmpp:"+this.getJid().toBareJid().toString(); String uri = "xmpp:"+this.getJid().toBareJid().toString();
if (fingerprints.size() > 0) { if (fingerprints.size() > 0) {
StringBuilder builder = new StringBuilder(uri); return XmppUri.getFingerprintUri(uri,fingerprints,';');
builder.append('?'); } else {
for(int i = 0; i < fingerprints.size(); ++i) { return uri;
XmppUri.FingerprintType type = fingerprints.get(i).type; }
if (type == XmppUri.FingerprintType.OMEMO) { }
builder.append(XmppUri.OMEMO_URI_PARAM);
builder.append(fingerprints.get(i).deviceId); public String getShareableLink() {
} else if (type == XmppUri.FingerprintType.OTR) { List<XmppUri.Fingerprint> fingerprints = this.getFingerprints();
builder.append(XmppUri.OTR_URI_PARAM); String uri = "https://conversations.im/i/"+this.getJid().toBareJid().toString();
} if (fingerprints.size() > 0) {
builder.append('='); return XmppUri.getFingerprintUri(uri,fingerprints,'&');
builder.append(fingerprints.get(i).fingerprint);
if (i != fingerprints.size() -1) {
builder.append(';');
}
}
return builder.toString();
} else { } else {
return uri; return uri;
} }

View file

@ -756,7 +756,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
intent.setType("text/plain"); intent.setType("text/plain");
String text; String text;
if (http) { if (http) {
text = "https://conversations.im/i/"+mAccount.getJid().toBareJid().toString(); text = mAccount.getShareableLink();
} else { } else {
text = mAccount.getShareableUri(); text = mAccount.getShareableUri();
} }

View file

@ -64,6 +64,7 @@ public class XmppUri {
jid = segments.get(1) + "@" + segments.get(2); jid = segments.get(1) + "@" + segments.get(2);
} }
muc = segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0)); muc = segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0));
fingerprints = parseFingerprints(uri.getQuery(),'&');
} else if ("xmpp".equalsIgnoreCase(scheme)) { } else if ("xmpp".equalsIgnoreCase(scheme)) {
// sample: xmpp:foo@bar.com // sample: xmpp:foo@bar.com
muc = isMuc(uri.getQuery()); muc = isMuc(uri.getQuery());
@ -166,6 +167,26 @@ public class XmppUri {
OTR OTR
} }
public static String getFingerprintUri(String base, List<XmppUri.Fingerprint> fingerprints, char seperator) {
StringBuilder builder = new StringBuilder(base);
builder.append('?');
for(int i = 0; i < fingerprints.size(); ++i) {
XmppUri.FingerprintType type = fingerprints.get(i).type;
if (type == XmppUri.FingerprintType.OMEMO) {
builder.append(XmppUri.OMEMO_URI_PARAM);
builder.append(fingerprints.get(i).deviceId);
} else if (type == XmppUri.FingerprintType.OTR) {
builder.append(XmppUri.OTR_URI_PARAM);
}
builder.append('=');
builder.append(fingerprints.get(i).fingerprint);
if (i != fingerprints.size() -1) {
builder.append(seperator);
}
}
return builder.toString();
}
public static class Fingerprint { public static class Fingerprint {
public final FingerprintType type; public final FingerprintType type;
public final String fingerprint; public final String fingerprint;