1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.template.*
6 import net.pterodactylus.sone.utils.*
7 import net.pterodactylus.sone.web.*
8 import net.pterodactylus.sone.web.page.*
9 import net.pterodactylus.util.template.*
14 * Lets the user browser another Sone.
16 @TemplatePath("/templates/viewSone.html")
17 @ToadletPath("viewSone.html")
18 class ViewSonePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
19 SoneTemplatePage(webInterface, loaders, templateRenderer) {
21 override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
22 templateContext["soneId"] = soneRequest.parameters["sone"]
23 soneRequest.parameters["sone"]!!.let(soneRequest.core::getSone)?.let { sone ->
24 templateContext["sone"] = sone
25 val sonePosts = sone.posts
26 val directedPosts = soneRequest.core.getDirectedPosts(sone.id)
27 (sonePosts + directedPosts)
28 .sortedByDescending(Post::getTime)
29 .paginate(soneRequest.core.preferences.postsPerPage)
30 .apply { page = soneRequest.parameters["postPage"]?.toIntOrNull() ?: 0 }
32 templateContext["postPagination"] = it
33 templateContext["posts"] = it.items
36 .mapPresent(PostReply::getPost)
40 .sortedByDescending { soneRequest.core.getReplies(it.id).first().time }
41 .paginate(soneRequest.core.preferences.postsPerPage)
42 .apply { page = soneRequest.parameters["repliedPostPage"]?.toIntOrNull() ?: 0 }
44 templateContext["repliedPostPagination"] = it
45 templateContext["repliedPosts"] = it.items
50 override fun isLinkExcepted(link: URI) = true
52 override fun getPageTitle(soneRequest: SoneRequest): String =
53 soneRequest.parameters["sone"]!!.let(soneRequest.core::getSone)?.let { sone ->
54 "${SoneAccessor.getNiceName(sone)} - ${translation.translate("Page.ViewSone.Title")}"
55 } ?: translation.translate("Page.ViewSone.Page.TitleWithoutSone")