Add test for DI constructability of CreateAlbumPage
[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
12 /**
13  * This page lets the user view a post and all its replies.
14  */
15 class ViewPostPage(template: Template, webInterface: WebInterface):
16                 SoneTemplatePage("viewPost.html", webInterface, template, "Page.ViewPost.Title") {
17
18         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
19                 templateContext["post"] = freenetRequest.parameters["post"]?.let(webInterface.core::getPost)
20                 templateContext["raw"] = freenetRequest.parameters["raw"] == "true"
21         }
22
23         override fun isLinkExcepted(link: URI?) = true
24
25         public override fun getPageTitle(freenetRequest: FreenetRequest) =
26                         (freenetRequest.parameters["post"]?.let(webInterface.core::getPost)?.let {
27                                 if (it.text.length > 20) {
28                                         it.text.substring(0..19) + "…"
29                                 } else {
30                                         it.text
31                                 } + " - ${SoneAccessor.getNiceName(it.sone)} - "
32                         } ?: "") + super.getPageTitle(freenetRequest)
33
34 }