🎨 Clean up imports
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / NewPage.kt
1 package net.pterodactylus.sone.web.pages
2
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.*
8 import javax.inject.*
9
10 /**
11  * Page that displays all new posts and replies. The posts are filtered using
12  * [PostVisibilityFilter.isPostVisible(Sone, Post)] and sorted by time.
13  */
14 @MenuName("New")
15 @TemplatePath("/templates/new.html")
16 class NewPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
17                 SoneTemplatePage("new.html", webInterface, loaders, templateRenderer, pageTitleKey = "Page.New.Title") {
18
19         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) =
20                         getCurrentSone(soneRequest.toadletContext).let { currentSone ->
21                                 (soneRequest.webInterface.getNewPosts(currentSone) + soneRequest.webInterface.getNewReplies(currentSone).mapPresent { it.post })
22                                                 .distinct()
23                                                 .sortedByDescending { it.time }
24                                                 .let { posts ->
25                                                         posts.paginate(soneRequest.core.preferences.postsPerPage)
26                                                                         .turnTo(soneRequest.parameters["page"]?.toIntOrNull() ?: 0)
27                                                                         .let { pagination ->
28                                                                                 templateContext["pagination"] = pagination
29                                                                                 templateContext["posts"] = pagination.items
30                                                                         }
31                                                 }
32                         }
33
34 }