X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetReplyAjaxPage.java;h=c66f47ad78e85d1bf1cdf6354af0db745c33833e;hp=61397764148de518362c32bd5c57db36523098e5;hb=2f4d45dce241da77f5109e97ba497f0dd4d5c1ec;hpb=d678616d36fce087fe89cdbc27f0169e7a612790 diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java index 6139776..c66f47a 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -1,5 +1,5 @@ /* - * Sone - GetReplyAjaxPage.java - Copyright © 2010–2013 David Roden + * Sone - GetReplyAjaxPage.java - Copyright © 2010–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 @@ -18,17 +18,22 @@ package net.pterodactylus.sone.web.ajax; import java.io.StringWriter; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; + +import com.google.common.base.Optional; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.io.Closer; -import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.template.TemplateException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + /** * This AJAX page returns the details of a reply. * @@ -60,13 +65,13 @@ public class GetReplyAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String replyId = request.getHttpRequest().getParam("reply"); - PostReply reply = webInterface.getCore().getPostReply(replyId); - if ((reply == null) || (reply.getSone() == null)) { + Optional reply = webInterface.getCore().getPostReply(replyId); + if (!reply.isPresent()) { return createErrorJsonObject("invalid-reply-id"); } - return createSuccessJsonObject().put("reply", createJsonReply(request, reply, getCurrentSone(request.getToadletContext()))); + return createSuccessJsonObject().put("reply", createJsonReply(request, reply.get(), getCurrentSone(request.getToadletContext()))); } /** @@ -92,10 +97,10 @@ public class GetReplyAjaxPage extends JsonPage { * The currently logged in Sone (to store in the template) * @return The JSON representation of the reply */ - private JsonObject createJsonReply(FreenetRequest request, PostReply reply, Sone currentSone) { - JsonObject jsonReply = new JsonObject(); + private JsonNode createJsonReply(FreenetRequest request, PostReply reply, Sone currentSone) { + ObjectNode jsonReply = new ObjectNode(instance); jsonReply.put("id", reply.getId()); - jsonReply.put("postId", reply.getPost().getId()); + jsonReply.put("postId", reply.getPostId()); jsonReply.put("soneId", reply.getSone().getId()); jsonReply.put("time", reply.getTime()); StringWriter stringWriter = new StringWriter();