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