1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.notify.PostVisibilityFilter
4 import net.pterodactylus.sone.utils.Pagination
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
12 * The index page shows the main page of Sone. This page will contain the posts
13 * of all friends of the current user.
15 class IndexPage(template: Template, webInterface: WebInterface, private val postVisibilityFilter: PostVisibilityFilter):
16 SoneTemplatePage("index.html", template, "Page.Index.Title", webInterface, true) {
18 override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
19 getCurrentSone(freenetRequest.toadletContext)!!.let { currentSone ->
22 .mapNotNull(webInterface.core::getSone)
23 .flatMap { it.posts } +
24 webInterface.core.getDirectedPosts(currentSone.id)
26 .filter { postVisibilityFilter.isVisible(currentSone).apply(it) }
27 .sortedByDescending { it.time }
29 Pagination(posts, webInterface.core.preferences.postsPerPage).apply {
30 page = freenetRequest.parameters["page"]?.toIntOrNull() ?: 0
32 templateContext["pagination"] = pagination
33 templateContext["posts"] = pagination.items