1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.utils.paginate
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 import javax.inject.Inject
12 * Page that lets the user browse all his bookmarked posts.
14 class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface) :
15 SoneTemplatePage("bookmarks.html", webInterface, template, "Page.Bookmarks.Title") {
17 override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
18 webInterface.core.bookmarkedPosts.let { posts ->
19 val pagination = posts.filter(Post::isLoaded).sortedByDescending { it.time }.paginate(webInterface.core.preferences.postsPerPage)
20 templateContext["pagination"] = pagination
21 templateContext["posts"] = pagination.items
22 templateContext["postsNotLoaded"] = posts.any { !it.isLoaded }