X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FTrustAjaxPage.java;h=d0247cb4155bf01e4ebb8d55a7e8940451d6b7d1;hb=d142608024302ca4106a70b95daabf27aa5362a4;hp=e298a50a6387c6d0ac68530efd46666ab07ce793;hpb=dad9ff0a8ce714441229fe1b4ec216294a18d5e7;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java
index e298a50..d0247cb 100644
--- a/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java
+++ b/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java
@@ -1,5 +1,5 @@
/*
- * Sone - TrustAjaxPage.java - Copyright © 2011 David Roden
+ * Sone - TrustAjaxPage.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
@@ -17,10 +17,14 @@
package net.pterodactylus.sone.web.ajax;
+import javax.annotation.Nonnull;
+
+import com.google.common.base.Optional;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Sone;
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 trust a Sone.
@@ -28,7 +32,7 @@ import net.pterodactylus.util.json.JsonObject;
* @see Core#trustSone(Sone, Sone)
* @author David âBombeâ Roden
*/
-public class TrustAjaxPage extends JsonPage {
+public class TrustAjaxPage extends LoggedInJsonPage {
/**
* Creates a new âtrust Soneâ AJAX handler.
@@ -43,19 +47,16 @@ public class TrustAjaxPage extends JsonPage {
/**
* {@inheritDoc}
*/
+ @Nonnull
@Override
- protected JsonObject createJsonObject(Request request) {
- Sone currentSone = getCurrentSone(request.getToadletContext(), false);
- if (currentSone == null) {
- return createErrorJsonObject("auth-required");
- }
+ protected JsonReturnObject createJsonObject(@Nonnull Sone currentSone, @Nonnull FreenetRequest request) {
String soneId = request.getHttpRequest().getParam("sone");
- Sone sone = webInterface.getCore().getSone(soneId, false);
- if (sone == null) {
+ Optional sone = webInterface.getCore().getSone(soneId);
+ if (!sone.isPresent()) {
return createErrorJsonObject("invalid-sone-id");
}
- webInterface.getCore().trustSone(currentSone, sone);
- return createSuccessJsonObject().put("trustValue", webInterface.getCore().getTrust(currentSone, sone).getExplicit());
+ webInterface.getCore().trustSone(currentSone, sone.get());
+ return createSuccessJsonObject().put("trustValue", webInterface.getCore().getPreferences().getPositiveTrust());
}
}