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();
String uri = "xmpp:"+this.getJid().toBareJid().toString();
if (fingerprints.size() > 0) {
StringBuilder builder = new StringBuilder(uri);
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(';');
}
}
return builder.toString();
return XmppUri.getFingerprintUri(uri,fingerprints,';');
} else {
return uri;
}
}
public String getShareableLink() {
List<XmppUri.Fingerprint> fingerprints = this.getFingerprints();
String uri = "https://conversations.im/i/"+this.getJid().toBareJid().toString();
if (fingerprints.size() > 0) {
return XmppUri.getFingerprintUri(uri,fingerprints,'&');
} else {
return uri;
}

View file

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

View file

@ -64,6 +64,7 @@ public class XmppUri {
jid = segments.get(1) + "@" + segments.get(2);
}
muc = segments.size() > 1 && "j".equalsIgnoreCase(segments.get(0));
fingerprints = parseFingerprints(uri.getQuery(),'&');
} else if ("xmpp".equalsIgnoreCase(scheme)) {
// sample: xmpp:foo@bar.com
muc = isMuc(uri.getQuery());
@ -166,6 +167,26 @@ public class XmppUri {
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 final FingerprintType type;
public final String fingerprint;