f6cdd0b9c5f66b089fd98b705a19b452ce9585ab
[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.paginate
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.*
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
9 import javax.inject.Inject
10
11 /**
12  * Page that lets the user browse all his bookmarked posts.
13  */
14 class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface) :
15                 SoneTemplatePage("bookmarks.html", webInterface, template, "Page.Bookmarks.Title") {
16
17         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
18                 soneRequest.core.bookmarkedPosts.let { posts ->
19                         val pagination = posts.filter(Post::isLoaded).sortedByDescending { it.time }.paginate(soneRequest.core.preferences.postsPerPage)
20                         templateContext["pagination"] = pagination
21                         templateContext["posts"] = pagination.items
22                         templateContext["postsNotLoaded"] = posts.any { !it.isLoaded }
23                 }
24         }
25
26 }