X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetPostAjaxPage.java;h=f56c5b7966da54e44390014a0c55d41dedafcc64;hb=b90831223c33e2284b409f9745151363e61f16aa;hp=452fc5adaa3daf1bd414466c256526fa23ab3dbf;hpb=2e3b2fb869041cd573ea2acd0623d2f499d4ab1b;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java index 452fc5a..f56c5b7 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java @@ -20,10 +20,12 @@ package net.pterodactylus.sone.web.ajax; import java.io.StringWriter; import net.pterodactylus.sone.data.Post; +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; /** @@ -46,7 +48,7 @@ public class GetPostAjaxPage extends JsonPage { * The template to render for posts */ public GetPostAjaxPage(WebInterface webInterface, Template postTemplate) { - super("ajax/getPost.ajax", webInterface); + super("getPost.ajax", webInterface); this.postTemplate = postTemplate; } @@ -60,8 +62,7 @@ public class GetPostAjaxPage extends JsonPage { if (post == null) { return createErrorJsonObject("invalid-post-id"); } - postTemplate.set("currentSone", getCurrentSone(request.getToadletContext())); - return createSuccessJsonObject().put("post", createJsonPost(post)); + return createSuccessJsonObject().put("post", createJsonPost(request, post, getCurrentSone(request.getToadletContext()))); } /** @@ -80,19 +81,29 @@ public class GetPostAjaxPage extends JsonPage { * Creates a JSON object from the given post. The JSON object will only * contain the ID of the post, its time, and its rendered HTML code. * + * @param request + * The request being processed * @param post * The post to create a JSON object from + * @param currentSone + * The currently logged in Sone (to store in the template) * @return The JSON representation of the post */ - private JsonObject createJsonPost(Post post) { + private JsonObject createJsonPost(Request request, Post post, Sone currentSone) { JsonObject jsonPost = new JsonObject(); jsonPost.put("id", post.getId()); jsonPost.put("sone", post.getSone().getId()); + jsonPost.put("recipient", (post.getRecipient() == null) ? null : post.getRecipient().getId()); jsonPost.put("time", post.getTime()); - postTemplate.set("post", post); StringWriter stringWriter = new StringWriter(); + TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext(); + templateContext.set("core", webInterface.getCore()); + templateContext.set("request", request); + templateContext.set("post", post); + templateContext.set("currentSone", currentSone); + templateContext.set("localSones", webInterface.getCore().getLocalSones()); try { - postTemplate.render(stringWriter); + postTemplate.render(templateContext, stringWriter); } catch (TemplateException te1) { /* TODO - shouldn’t happen. */ } finally {