X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FTrustAjaxPage.java;h=1225de16f6ad2d92ca53f44e3276909c914ac479;hb=53a71d1d6b91e4d56af49a06f2e06bc4d11bf3eb;hp=5b27d1bd9c53dacf0ce3f2a97f88538faf649959;hpb=61fea0173ef87542cae35247e6356ef36f2664d3;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 5b27d1b..1225de1 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–2012 David Roden + * Sone - TrustAjaxPage.java - Copyright © 2011–2013 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,11 +17,12 @@ 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.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; /** * AJAX page that lets the user trust a Sone. @@ -45,17 +46,14 @@ public class TrustAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { - Sone currentSone = getCurrentSone(request.getToadletContext(), false); - if (currentSone == null) { - return createErrorJsonObject("auth-required"); - } + protected JsonReturnObject createJsonObject(FreenetRequest request) { + Sone currentSone = getCurrentSone(request.getToadletContext(), false).get(); 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); + webInterface.getCore().trustSone(currentSone, sone.get()); return createSuccessJsonObject().put("trustValue", webInterface.getCore().getPreferences().getPositiveTrust()); }