Replace Sone change detector with simple comparison helper
[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.FreenetRequest
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(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 }
23                 }
24         }
25
26 }