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