🎨 Replace image count comparator with Kotlin version
[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.main.*
4 import net.pterodactylus.sone.template.*
5 import net.pterodactylus.sone.utils.*
6 import net.pterodactylus.sone.web.*
7 import net.pterodactylus.sone.web.page.*
8 import net.pterodactylus.util.template.*
9 import java.net.*
10 import javax.inject.*
11
12 /**
13  * This page lets the user view a post and all its replies.
14  */
15 @TemplatePath("/templates/viewPost.html")
16 @ToadletPath("viewPost.html")
17 class ViewPostPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
18                 SoneTemplatePage(webInterface, loaders, templateRenderer, pageTitleKey = "Page.ViewPost.Title") {
19
20         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
21                 templateContext["post"] = soneRequest.parameters["post"]?.let(soneRequest.core::getPost)
22                 templateContext["raw"] = soneRequest.parameters["raw"] == "true"
23         }
24
25         override fun isLinkExcepted(link: URI) = true
26
27         override fun getPageTitle(soneRequest: SoneRequest) =
28                         (soneRequest.parameters["post"]?.let(soneRequest.core::getPost)?.let {
29                                 if (it.text.length > 20) {
30                                         it.text.substring(0..19) + "…"
31                                 } else {
32                                         it.text
33                                 } + " - ${SoneAccessor.getNiceName(it.sone)} - "
34                         } ?: "") + super.getPageTitle(soneRequest)
35
36 }