1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.utils.Pagination
4 import net.pterodactylus.sone.utils.mapPresent
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 * Page that displays all new posts and replies. The posts are filtered using
13 * [PostVisibilityFilter.isPostVisible(Sone, Post)] and sorted by time.
15 class NewPage(template: Template, webInterface: WebInterface):
16 SoneTemplatePage("new.html", webInterface, template, "Page.New.Title") {
18 override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) =
19 getCurrentSone(freenetRequest.toadletContext).let { currentSone ->
20 (webInterface.getNewPosts(currentSone) + webInterface.getNewReplies(currentSone).mapPresent { it.post })
22 .sortedByDescending { it.time }
24 Pagination(posts, webInterface.core.preferences.postsPerPage).apply {
25 page = freenetRequest.parameters["page"]?.toIntOrNull() ?: 0
27 templateContext["pagination"] = pagination
28 templateContext["posts"] = pagination.items