X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetPostAjaxPage.kt;h=7f1ce6eff3950536a93b41889f52be279dcb55f3;hp=3c35125c623e769e4c30994124b9fd9ea3a7ea0e;hb=7afd66a21244e757b6b49ba96bb3989bc55a2abf;hpb=0197f5a0dda9f60255f4a19cabf7ef7f2f2eaa19 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt index 3c35125..7f1ce6e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.kt @@ -3,25 +3,25 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.data.Post import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.jsonObject -import net.pterodactylus.sone.utils.let import net.pterodactylus.sone.utils.parameters +import net.pterodactylus.sone.utils.render import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template -import net.pterodactylus.util.template.TemplateContext -import java.io.StringWriter +import javax.inject.Inject /** * This AJAX handler retrieves information and rendered representation of a [Post]. */ -class GetPostAjaxPage(webInterface: WebInterface, private val postTemplate: Template) : LoggedInJsonPage("getPost.ajax", webInterface) { +class GetPostAjaxPage @Inject constructor(webInterface: WebInterface, private val postTemplate: Template) : + LoggedInJsonPage("getPost.ajax", webInterface) { - override fun needsFormPassword() = false + override val needsFormPassword = false override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = request.parameters["post"] - .let(webInterface.core::getPost) - .let { post -> + ?.let(core::getPost) + ?.let { post -> createSuccessJsonObject(). put("post", jsonObject( "id" to post.id, @@ -34,13 +34,11 @@ class GetPostAjaxPage(webInterface: WebInterface, private val postTemplate: Temp private fun Post.render(currentSone: Sone, request: FreenetRequest) = webInterface.templateContextFactory.createTemplateContext().apply { - set("core", webInterface.core) + set("core", core) set("request", request) set("post", this@render) set("currentSone", currentSone) - set("localSones", webInterface.core.localSones) + set("localSones", core.localSones) }.let { postTemplate.render(it) } } - -private fun Template.render(templateContext: TemplateContext) = StringWriter().use { it.also { render(templateContext, it) } }.toString()