X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetReplyAjaxPage.java;h=6cc7d4707ac22c4b1cd993fc8ea1f5e70ed006fe;hb=b90831223c33e2284b409f9745151363e61f16aa;hp=77b3ada9b23dfbcd7da45dffe4c8e238656fe3ec;hpb=6db033602e7c17efc40a4a19efe705d67832fc1a;p=Sone.git 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 77b3ada..6cc7d47 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -20,10 +20,12 @@ package net.pterodactylus.sone.web.ajax; import java.io.StringWriter; import net.pterodactylus.sone.data.Reply; +import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; 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; /** @@ -63,8 +65,7 @@ public class GetReplyAjaxPage extends JsonPage { if ((reply == null) || (reply.getSone() == null)) { return createErrorJsonObject("invalid-reply-id"); } - replyTemplate.set("currentSone", getCurrentSone(request.getToadletContext())); - return createSuccessJsonObject().put("reply", createJsonReply(reply)); + return createSuccessJsonObject().put("reply", createJsonReply(request, reply, getCurrentSone(request.getToadletContext()))); } /** @@ -82,20 +83,28 @@ public class GetReplyAjaxPage extends JsonPage { /** * Creates a JSON representation of the given reply. * + * @param request + * The request being processed * @param reply * The reply to convert + * @param currentSone + * The currently logged in Sone (to store in the template) * @return The JSON representation of the reply */ - private JsonObject createJsonReply(Reply reply) { + private JsonObject createJsonReply(Request request, Reply reply, Sone currentSone) { JsonObject jsonReply = new JsonObject(); jsonReply.put("id", reply.getId()); jsonReply.put("postId", reply.getPost().getId()); jsonReply.put("soneId", reply.getSone().getId()); jsonReply.put("time", reply.getTime()); - replyTemplate.set("reply", reply); StringWriter stringWriter = new StringWriter(); + TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext(); + templateContext.set("core", webInterface.getCore()); + templateContext.set("request", request); + templateContext.set("reply", reply); + templateContext.set("currentSone", currentSone); try { - replyTemplate.render(stringWriter); + replyTemplate.render(templateContext, stringWriter); } catch (TemplateException te1) { /* TODO - shouldn’t happen. */ } finally {