1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.notify.PostVisibilityFilter
6 import net.pterodactylus.sone.utils.paginate
7 import net.pterodactylus.sone.utils.parameters
8 import net.pterodactylus.sone.web.WebInterface
9 import net.pterodactylus.sone.web.page.*
10 import net.pterodactylus.util.template.Template
11 import net.pterodactylus.util.template.TemplateContext
12 import javax.inject.Inject
15 * The index page shows the main page of Sone. This page will contain the posts
16 * of all friends of the current user.
19 @TemplatePath("/templates/index.html")
20 class IndexPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, private val postVisibilityFilter: PostVisibilityFilter) :
21 LoggedInPage("index.html", template, "Page.Index.Title", webInterface, loaders, templateRenderer) {
23 override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
26 .mapNotNull(soneRequest.core::getSone)
27 .flatMap { it.posts } +
28 soneRequest.core.getDirectedPosts(currentSone.id)
30 .filter { postVisibilityFilter.isVisible(currentSone).apply(it) }
31 .sortedByDescending { it.time }
33 posts.paginate(soneRequest.core.preferences.postsPerPage)
34 .turnTo(soneRequest.parameters["page"]?.toIntOrNull() ?: 0)
36 templateContext["pagination"] = pagination
37 templateContext["posts"] = pagination.items