Skip to content

Commit bce2f85

Browse files
committed
Improve proofLabels to handle more than twitter/github and the only the first (!) listed site
1 parent 7f4980f commit bce2f85

File tree

1 file changed

+35
-3
lines changed
  • Lib/src/main/java/com/textuality/keybase/lib

1 file changed

+35
-3
lines changed

Lib/src/main/java/com/textuality/keybase/lib/Match.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import org.json.JSONObject;
2222

2323
import java.util.ArrayList;
24+
import java.util.Hashtable;
2425
import java.util.List;
26+
import java.util.Set;
2527

2628
public class Match {
2729
private final JSONObject mComponents;
@@ -86,18 +88,48 @@ public int getBitStrength() throws KeybaseException {
8688
public List<String> getProofLabels() {
8789
ArrayList<String> labels = new ArrayList<String>();
8890
try {
89-
labels.add("twitter.com/" + JWalk.getString(mComponents, "twitter", "val"));
91+
labels.add("Twitter: @" + JWalk.getString(mComponents, "twitter", "val"));
9092
} catch (JSONException e) {
9193
// s'OK
9294
}
9395
try {
94-
labels.add("github.com/" + JWalk.getString(mComponents, "github", "val"));
96+
labels.add("GitHub: " + JWalk.getString(mComponents, "github", "val"));
97+
} catch (JSONException e) {
98+
// s'OK
99+
}
100+
try {
101+
labels.add("Reddit: " + JWalk.getString(mComponents, "reddit", "val"));
102+
} catch (JSONException e) {
103+
// s'OK
104+
}
105+
try {
106+
labels.add("Hacker News: " + JWalk.getString(mComponents, "hackernews", "val"));
107+
} catch (JSONException e) {
108+
// s'OK
109+
}
110+
try {
111+
labels.add("Coinbase: " + JWalk.getString(mComponents, "coinbase", "val"));
95112
} catch (JSONException e) {
96113
// s'OK
97114
}
98115
try {
99116
JSONArray sites = JWalk.getArray(mComponents, "websites");
100-
labels.add(JWalk.getString(sites.getJSONObject(0), "val"));
117+
Hashtable<String, Integer> uniqueNames = new Hashtable<String, Integer>();
118+
int i;
119+
for (i = 0; i < sites.length(); i++) {
120+
uniqueNames.put(JWalk.getString(sites.getJSONObject(i), "val"), 1);
121+
}
122+
Set<String> names = uniqueNames.keySet();
123+
StringBuilder label = new StringBuilder("Web: ");
124+
i = 0;
125+
for (String name : names) {
126+
label.append(name);
127+
if (i < names.size() - 1) {
128+
label.append(", ");
129+
}
130+
i++;
131+
}
132+
labels.add(label.toString());
101133
} catch (JSONException e) {
102134
// s'OK
103135
}

0 commit comments

Comments
 (0)