X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FViewSonePage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FViewSonePage.kt;h=6903920c19189f8ac4abc8a0376cc049f442859d;hp=0000000000000000000000000000000000000000;hb=5096eaa5c9259972a07ba5fec125dc9103d727bd;hpb=1bd4979e2d3da9d4e9f400f054e6e1d91890669b diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt new file mode 100644 index 0000000..6903920 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt @@ -0,0 +1,58 @@ +package net.pterodactylus.sone.web.pages + +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.PostReply +import net.pterodactylus.sone.template.SoneAccessor +import net.pterodactylus.sone.utils.let +import net.pterodactylus.sone.utils.mapPresent +import net.pterodactylus.sone.utils.paginate +import net.pterodactylus.sone.utils.parameters +import net.pterodactylus.sone.web.WebInterface +import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.util.template.Template +import net.pterodactylus.util.template.TemplateContext +import java.net.URI + +/** + * Lets the user browser another Sone. + */ +class ViewSonePage(template: Template, webInterface: WebInterface): + SoneTemplatePage("viewSone.html", template, webInterface, false) { + + override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { + templateContext["soneId"] = request.parameters["sone"] + request.parameters["sone"].let(webInterface.core::getSone).let { sone -> + templateContext["sone"] = sone + val sonePosts = sone.posts + val directedPosts = webInterface.core.getDirectedPosts(sone.id) + (sonePosts + directedPosts) + .sortedByDescending(Post::getTime) + .paginate(webInterface.core.preferences.postsPerPage) + .apply { page = request.parameters["postPage"]?.toIntOrNull() ?: 0 } + .also { + templateContext["postPagination"] = it + templateContext["posts"] = it.items + } + sone.replies + .mapPresent(PostReply::getPost) + .distinct() + .minus(sonePosts) + .minus(directedPosts) + .sortedByDescending { webInterface.core.getReplies(it.id).first().time } + .paginate(webInterface.core.preferences.postsPerPage) + .apply { page = request.parameters["repliedPostPage"]?.toIntOrNull() ?: 0 } + .also { + templateContext["repliedPostPagination"] = it + templateContext["repliedPosts"] = it.items + } + } + } + + override fun isLinkExcepted(link: URI?) = true + + public override fun getPageTitle(request: FreenetRequest): String = + request.parameters["sone"].let(webInterface.core::getSone).let { sone -> + "${SoneAccessor.getNiceName(sone)} - ${webInterface.l10n.getString("Page.ViewSone.Title")}" + } ?: webInterface.l10n.getString("Page.ViewSone.Page.TitleWithoutSone") + +}