mirror of https://github.com/zlatinb/muwire
wip on trust subscriptions
parent
300938fa44
commit
662b065116
|
@ -62,6 +62,10 @@ class TrustSubscriber {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSubscribed(Persona p) {
|
||||||
|
remoteTrustLists.containsKey(p.destination)
|
||||||
|
}
|
||||||
|
|
||||||
private void checkLoop() {
|
private void checkLoop() {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import com.muwire.core.trust.TrustEvent;
|
||||||
import com.muwire.core.trust.TrustLevel;
|
import com.muwire.core.trust.TrustLevel;
|
||||||
import com.muwire.core.trust.TrustService;
|
import com.muwire.core.trust.TrustService;
|
||||||
import com.muwire.core.trust.TrustService.TrustEntry;
|
import com.muwire.core.trust.TrustService.TrustEntry;
|
||||||
|
import com.muwire.core.trust.TrustSubscriber;
|
||||||
import com.muwire.core.trust.TrustSubscriptionEvent;
|
import com.muwire.core.trust.TrustSubscriptionEvent;
|
||||||
|
|
||||||
import net.i2p.data.Base64;
|
import net.i2p.data.Base64;
|
||||||
|
@ -44,13 +45,13 @@ public class TrustServlet extends HttpServlet {
|
||||||
|
|
||||||
sb.append("<Trusted>");
|
sb.append("<Trusted>");
|
||||||
for (TrustEntry te : core.getTrustService().getGood().values()) {
|
for (TrustEntry te : core.getTrustService().getGood().values()) {
|
||||||
TEtoXML(te,sb);
|
TEtoXML(te,sb, core.getTrustSubscriber());
|
||||||
}
|
}
|
||||||
sb.append("</Trusted>");
|
sb.append("</Trusted>");
|
||||||
|
|
||||||
sb.append("<Distrusted>");
|
sb.append("<Distrusted>");
|
||||||
for (TrustEntry te : core.getTrustService().getBad().values()) {
|
for (TrustEntry te : core.getTrustService().getBad().values()) {
|
||||||
TEtoXML(te, sb);
|
TEtoXML(te, sb, core.getTrustSubscriber());
|
||||||
}
|
}
|
||||||
sb.append("</Distrusted>");
|
sb.append("</Distrusted>");
|
||||||
|
|
||||||
|
@ -168,11 +169,12 @@ public class TrustServlet extends HttpServlet {
|
||||||
trustManager = (TrustManager) config.getServletContext().getAttribute("trustManager");
|
trustManager = (TrustManager) config.getServletContext().getAttribute("trustManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TEtoXML(TrustEntry te, StringBuilder sb) {
|
private static void TEtoXML(TrustEntry te, StringBuilder sb, TrustSubscriber trustSubscriber) {
|
||||||
sb.append("<Persona>");
|
sb.append("<Persona>");
|
||||||
sb.append("<User>").append(Util.escapeHTMLinXML(te.getPersona().getHumanReadableName())).append("</User>");
|
sb.append("<User>").append(Util.escapeHTMLinXML(te.getPersona().getHumanReadableName())).append("</User>");
|
||||||
sb.append("<UserB64>").append(te.getPersona().toBase64()).append("</UserB64>");
|
sb.append("<UserB64>").append(te.getPersona().toBase64()).append("</UserB64>");
|
||||||
sb.append("<Reason>").append(Util.escapeHTMLinXML(te.getReason())).append("</Reason>");
|
sb.append("<Reason>").append(Util.escapeHTMLinXML(te.getReason())).append("</Reason>");
|
||||||
|
sb.append("<Subscribed>").append(trustSubscriber.isSubscribed(te.getPersona())).append("</Subscribed>");
|
||||||
sb.append("</Persona>");
|
sb.append("</Persona>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,11 @@ class Persona {
|
||||||
constructor(xmlNode) {
|
constructor(xmlNode) {
|
||||||
this.user = xmlNode.getElementsByTagName("User")[0].childNodes[0].nodeValue
|
this.user = xmlNode.getElementsByTagName("User")[0].childNodes[0].nodeValue
|
||||||
this.userB64 = xmlNode.getElementsByTagName("UserB64")[0].childNodes[0].nodeValue
|
this.userB64 = xmlNode.getElementsByTagName("UserB64")[0].childNodes[0].nodeValue
|
||||||
this.reason = xmlNode.getElementsByTagName("Reason")[0].childNodes[0].nodeValue
|
this.subscribed = xmlNode.getElementsByTagName("Subscribed")[0].childNodes[0].nodeValue
|
||||||
|
this.reason = ""
|
||||||
|
try {
|
||||||
|
this.reason = xmlNode.getElementsByTagName("Reason")[0].childNodes[0].nodeValue
|
||||||
|
} catch (ignore) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
getTrustedLink() {
|
getTrustedLink() {
|
||||||
|
@ -16,12 +20,28 @@ class Persona {
|
||||||
getDistrustedLink() {
|
getDistrustedLink() {
|
||||||
return "<a herf='#' onclick='window.markDistrusted(\"" + this.userB64 + "\"); return false;'>Mark Distrusted</a>"
|
return "<a herf='#' onclick='window.markDistrusted(\"" + this.userB64 + "\"); return false;'>Mark Distrusted</a>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubscribeLink() {
|
||||||
|
return "<a href='#' onclick='window.subscribe(\"" + this.userB64 + "\"); return false;'>Subscribe</a>"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var trusted = new Map()
|
var trusted = new Map()
|
||||||
var distrusted = new Map()
|
var distrusted = new Map()
|
||||||
var revision = -1
|
var revision = -1
|
||||||
|
|
||||||
|
function subscribe(host) {
|
||||||
|
var xmlhttp = new XMLHttpRequest()
|
||||||
|
xmlhttp.onreadystatechange = function() {
|
||||||
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
|
refreshUsers()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xmlhttp.open("POST","/MuWire/Trust", true)
|
||||||
|
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||||
|
xmlhttp.send("action=subscribe&persona=" + host)
|
||||||
|
}
|
||||||
|
|
||||||
function markTrusted(host) {
|
function markTrusted(host) {
|
||||||
var linkSpan = document.getElementById("trusted-link-"+host)
|
var linkSpan = document.getElementById("trusted-link-"+host)
|
||||||
linkSpan.innerHTML = ""
|
linkSpan.innerHTML = ""
|
||||||
|
@ -99,7 +119,7 @@ function cancelDistrust(host) {
|
||||||
|
|
||||||
function updateTable(map, divId) {
|
function updateTable(map, divId) {
|
||||||
var divElement = document.getElementById(divId)
|
var divElement = document.getElementById(divId)
|
||||||
var tableHtml = "<table><thead><tr><th>User</th><th>Reason</th><th>Actions</th></tr></thead><tbody>"
|
var tableHtml = "<table><thead><tr><th>User</th><th>Reason</th><th>Actions</th><th>Subscribe</th></tr></thead><tbody>"
|
||||||
|
|
||||||
var isTrusted = (map == trusted)
|
var isTrusted = (map == trusted)
|
||||||
for (var [ignored, user] of map) {
|
for (var [ignored, user] of map) {
|
||||||
|
@ -117,6 +137,13 @@ function updateTable(map, divId) {
|
||||||
}
|
}
|
||||||
tableHtml += "</td>"
|
tableHtml += "</td>"
|
||||||
|
|
||||||
|
if (user.subscribed == "true") {
|
||||||
|
tableHtml += "<td>Subscribed</td>"
|
||||||
|
} else if (isTrusted) {
|
||||||
|
tableHtml += "<td>" + user.getSubscribeLink() + "</td>"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
tableHtml += "</tr>"
|
tableHtml += "</tr>"
|
||||||
}
|
}
|
||||||
tableHtml += "</tbody></table>"
|
tableHtml += "</tbody></table>"
|
||||||
|
|
Loading…
Reference in New Issue