1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.utils.mapPresent
4 import net.pterodactylus.sone.utils.paginate
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
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.
16 class NewPage @Inject constructor( template: Template, webInterface: WebInterface):
17 SoneTemplatePage("new.html", webInterface, template, "Page.New.Title") {
19 override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) =
20 getCurrentSone(freenetRequest.toadletContext).let { currentSone ->
21 (webInterface.getNewPosts(currentSone) + webInterface.getNewReplies(currentSone).mapPresent { it.post })
23 .sortedByDescending { it.time }
25 posts.paginate(webInterface.core.preferences.postsPerPage)
26 .turnTo(freenetRequest.parameters["page"]?.toIntOrNull() ?: 0)
28 templateContext["pagination"] = pagination
29 templateContext["posts"] = pagination.items