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.let
7 import net.pterodactylus.sone.utils.mapPresent
8 import net.pterodactylus.sone.utils.paginate
9 import net.pterodactylus.sone.utils.parameters
10 import net.pterodactylus.sone.web.WebInterface
11 import net.pterodactylus.sone.web.page.FreenetRequest
12 import net.pterodactylus.util.template.Template
13 import net.pterodactylus.util.template.TemplateContext
17 * Lets the user browser another Sone.
19 class ViewSonePage(template: Template, webInterface: WebInterface):
20 SoneTemplatePage("viewSone.html", template, webInterface, false) {
22 override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
23 templateContext["soneId"] = request.parameters["sone"]
24 request.parameters["sone"].let(webInterface.core::getSone).let { sone ->
25 templateContext["sone"] = sone
26 val sonePosts = sone.posts
27 val directedPosts = webInterface.core.getDirectedPosts(sone.id)
28 (sonePosts + directedPosts)
29 .sortedByDescending(Post::getTime)
30 .paginate(webInterface.core.preferences.postsPerPage)
31 .apply { page = request.parameters["postPage"]?.toIntOrNull() ?: 0 }
33 templateContext["postPagination"] = it
34 templateContext["posts"] = it.items
37 .mapPresent(PostReply::getPost)
41 .sortedByDescending { webInterface.core.getReplies(it.id).first().time }
42 .paginate(webInterface.core.preferences.postsPerPage)
43 .apply { page = request.parameters["repliedPostPage"]?.toIntOrNull() ?: 0 }
45 templateContext["repliedPostPagination"] = it
46 templateContext["repliedPosts"] = it.items
51 override fun isLinkExcepted(link: URI?) = true
53 public override fun getPageTitle(request: FreenetRequest): String =
54 request.parameters["sone"].let(webInterface.core::getSone).let { sone ->
55 "${SoneAccessor.getNiceName(sone)} - ${webInterface.l10n.getString("Page.ViewSone.Title")}"
56 } ?: webInterface.l10n.getString("Page.ViewSone.Page.TitleWithoutSone")