1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.main.Loaders
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.NewElements
8 import net.pterodactylus.sone.web.WebInterface
9 import net.pterodactylus.sone.web.page.MenuName
10 import net.pterodactylus.sone.web.page.SoneRequest
11 import net.pterodactylus.sone.web.page.TemplatePath
12 import net.pterodactylus.sone.web.page.TemplateRenderer
13 import net.pterodactylus.sone.web.page.ToadletPath
14 import net.pterodactylus.util.template.TemplateContext
15 import javax.inject.Inject
18 * Page that displays all new posts and replies. The posts are filtered using
19 * [PostVisibilityFilter.isPostVisible(Sone, Post)] and sorted by time.
22 @TemplatePath("/templates/new.html")
23 @ToadletPath("new.html")
24 class NewPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, private val newElements: NewElements) :
25 SoneTemplatePage(webInterface, loaders, templateRenderer, pageTitleKey = "Page.New.Title") {
27 override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) =
28 getCurrentSone(soneRequest.toadletContext).let { currentSone ->
29 (newElements.newPosts + newElements.newReplies.mapPresent { it.post })
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