Clean up SoneTemplatePage’s constructors
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / BookmarksPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.utils.Pagination
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.FreenetRequest
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
9
10 /**
11  * Page that lets the user browse all his bookmarked posts.
12  */
13 class BookmarksPage(template: Template, webInterface: WebInterface) :
14                 SoneTemplatePage("bookmarks.html", webInterface, template, "Page.Bookmarks.Title") {
15
16         override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
17                 webInterface.core.bookmarkedPosts.let { posts ->
18                         val pagination = Pagination<Post>(posts.filter { it.isLoaded }.sortedByDescending { it.time }, webInterface.core.preferences.postsPerPage)
19                         templateContext["pagination"] = pagination
20                         templateContext["posts"] = pagination.items
21                         templateContext["postsNotLoaded"] = posts.any { !it.isLoaded }
22                 }
23         }
24
25 }