1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.text.TextFilter
5 import net.pterodactylus.sone.utils.isPOST
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
13 * This page lets the user post a reply to a post.
15 class CreateReplyPage @Inject constructor(template: Template, webInterface: WebInterface):
16 LoggedInPage("createReply.html", template, "Page.CreateReply.Title", webInterface) {
18 override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) {
19 val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this }
20 val text = freenetRequest.httpRequest.getPartAsStringFailsafe("text", 65536).trim().apply { templateContext["text"] = this }
21 val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256).apply { templateContext["returnPage"] = this }
22 if (freenetRequest.isPOST) {
24 templateContext["errorTextEmpty"] = true
27 val post = webInterface.core.getPost(postId) ?: throw RedirectException("noPermission.html")
28 val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
29 webInterface.core.createReply(sender, post, TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text))
30 throw RedirectException(returnPage)