Fix search for Sone elements
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / ViewPostPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.template.SoneAccessor
4 import net.pterodactylus.sone.utils.let
5 import net.pterodactylus.sone.utils.parameters
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 java.net.URI
11 import javax.inject.Inject
12
13 /**
14  * This page lets the user view a post and all its replies.
15  */
16 class ViewPostPage @Inject constructor(template: Template, webInterface: WebInterface):
17                 SoneTemplatePage("viewPost.html", webInterface, template, "Page.ViewPost.Title") {
18
19         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
20                 templateContext["post"] = freenetRequest.parameters["post"]?.let(webInterface.core::getPost)
21                 templateContext["raw"] = freenetRequest.parameters["raw"] == "true"
22         }
23
24         override fun isLinkExcepted(link: URI?) = true
25
26         public override fun getPageTitle(freenetRequest: FreenetRequest) =
27                         (freenetRequest.parameters["post"]?.let(webInterface.core::getPost)?.let {
28                                 if (it.text.length > 20) {
29                                         it.text.substring(0..19) + "…"
30                                 } else {
31                                         it.text
32                                 } + " - ${SoneAccessor.getNiceName(it.sone)} - "
33                         } ?: "") + super.getPageTitle(freenetRequest)
34
35 }