1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.main.*
4 import net.pterodactylus.sone.utils.mapPresent
5 import net.pterodactylus.sone.utils.paginate
6 import net.pterodactylus.sone.utils.parameters
7 import net.pterodactylus.sone.web.WebInterface
8 import net.pterodactylus.sone.web.page.*
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
13 * Page that displays all new posts and replies. The posts are filtered using
14 * [PostVisibilityFilter.isPostVisible(Sone, Post)] and sorted by time.
17 @TemplatePath("/templates/new.html")
18 class NewPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
19 SoneTemplatePage("new.html", webInterface, loaders, templateRenderer, pageTitleKey = "Page.New.Title") {
21 override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) =
22 getCurrentSone(soneRequest.toadletContext).let { currentSone ->
23 (soneRequest.webInterface.getNewPosts(currentSone) + soneRequest.webInterface.getNewReplies(currentSone).mapPresent { it.post })
25 .sortedByDescending { it.time }
27 posts.paginate(soneRequest.core.preferences.postsPerPage)
28 .turnTo(soneRequest.parameters["page"]?.toIntOrNull() ?: 0)
30 templateContext["pagination"] = pagination
31 templateContext["posts"] = pagination.items