X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetReplyAjaxPage.java;h=c19bcba4169f4201724b2470ded7238efb7beb64;hb=9e4db46b86d084eba9029906e779ec1d96f78ac4;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..c19bcba 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(reply, getCurrentSone(request.getToadletContext()))); } /** @@ -84,18 +85,22 @@ public class GetReplyAjaxPage extends JsonPage { * * @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(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("reply", reply); + templateContext.set("currentSone", currentSone); try { - replyTemplate.render(stringWriter); + replyTemplate.render(templateContext, stringWriter); } catch (TemplateException te1) { /* TODO - shouldn’t happen. */ } finally {