X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FViewSonePage.kt;h=ef0d3f5edb5f74864debc866ed7a52dfb9517b4b;hp=6903920c19189f8ac4abc8a0376cc049f442859d;hb=4526c36c096204837d478ac3a74fd78660eb20f5;hpb=5096eaa5c9259972a07ba5fec125dc9103d727bd diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt index 6903920..ef0d3f5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt @@ -3,7 +3,6 @@ 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 @@ -12,23 +11,24 @@ import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext import java.net.URI +import javax.inject.Inject /** * Lets the user browser another Sone. */ -class ViewSonePage(template: Template, webInterface: WebInterface): - SoneTemplatePage("viewSone.html", template, webInterface, false) { +class ViewSonePage @Inject constructor(template: Template, webInterface: WebInterface): + SoneTemplatePage("viewSone.html", webInterface, template) { - override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - templateContext["soneId"] = request.parameters["sone"] - request.parameters["sone"].let(webInterface.core::getSone).let { sone -> + override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { + templateContext["soneId"] = freenetRequest.parameters["sone"] + freenetRequest.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 } + .apply { page = freenetRequest.parameters["postPage"]?.toIntOrNull() ?: 0 } .also { templateContext["postPagination"] = it templateContext["posts"] = it.items @@ -40,7 +40,7 @@ class ViewSonePage(template: Template, webInterface: WebInterface): .minus(directedPosts) .sortedByDescending { webInterface.core.getReplies(it.id).first().time } .paginate(webInterface.core.preferences.postsPerPage) - .apply { page = request.parameters["repliedPostPage"]?.toIntOrNull() ?: 0 } + .apply { page = freenetRequest.parameters["repliedPostPage"]?.toIntOrNull() ?: 0 } .also { templateContext["repliedPostPagination"] = it templateContext["repliedPosts"] = it.items @@ -50,8 +50,8 @@ class ViewSonePage(template: Template, webInterface: WebInterface): override fun isLinkExcepted(link: URI?) = true - public override fun getPageTitle(request: FreenetRequest): String = - request.parameters["sone"].let(webInterface.core::getSone).let { sone -> + public override fun getPageTitle(freenetRequest: FreenetRequest): String = + freenetRequest.parameters["sone"]!!.let(webInterface.core::getSone)?.let { sone -> "${SoneAccessor.getNiceName(sone)} - ${webInterface.l10n.getString("Page.ViewSone.Title")}" } ?: webInterface.l10n.getString("Page.ViewSone.Page.TitleWithoutSone")