/*
- * Sone - TrustAjaxPage.java - Copyright © 2011 David Roden
+ * Sone - DistrustAjaxPage.java - Copyright © 2011–2016 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
package net.pterodactylus.sone.web.ajax;
+import com.google.common.base.Optional;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.sone.web.WebInterface;
-import net.pterodactylus.util.json.JsonObject;
+import net.pterodactylus.sone.web.page.FreenetRequest;
/**
* AJAX page that lets the user distrust a Sone.
* {@inheritDoc}
*/
@Override
- protected JsonObject createJsonObject(Request request) {
- Sone currentSone = getCurrentSone(request.getToadletContext(), false);
+ protected JsonReturnObject createJsonObject(FreenetRequest request) {
+ Sone currentSone = getCurrentSoneWithoutCreatingSession(request.getToadletContext());
if (currentSone == null) {
return createErrorJsonObject("auth-required");
}
String soneId = request.getHttpRequest().getParam("sone");
- Sone sone = webInterface.getCore().getSone(soneId, false);
- if (sone == null) {
+ Optional<Sone> sone = webInterface.getCore().getSone(soneId);
+ if (!sone.isPresent()) {
return createErrorJsonObject("invalid-sone-id");
}
- webInterface.getCore().distrustSone(currentSone, sone);
- Trust trust = webInterface.getCore().getTrust(currentSone, sone);
- if (trust == null) {
- return createErrorJsonObject("wot-plugin");
- }
- return createSuccessJsonObject().put("trustValue", trust.getExplicit());
+ webInterface.getCore().distrustSone(currentSone, sone.get());
+ return createSuccessJsonObject().put("trustValue", webInterface.getCore().getPreferences().getNegativeTrust());
}
}