1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.utils.also
5 import net.pterodactylus.sone.utils.isGET
6 import net.pterodactylus.sone.utils.isPOST
7 import net.pterodactylus.sone.utils.parameters
8 import net.pterodactylus.sone.web.WebInterface
9 import net.pterodactylus.sone.web.page.FreenetRequest
10 import net.pterodactylus.util.template.Template
11 import net.pterodactylus.util.template.TemplateContext
14 * Page that lets the user unbookmark a post.
16 class UnbookmarkPage(template: Template, webInterface: WebInterface):
17 SoneTemplatePage("unbookmark.html", webInterface, template, "Page.Unbookmark.Title") {
19 override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
21 freenetRequest.isGET && (freenetRequest.parameters["post"] == "allNotLoaded") -> {
22 webInterface.core.bookmarkedPosts
23 .filterNot(Post::isLoaded)
24 .forEach(webInterface.core::unbookmarkPost)
25 throw RedirectException("bookmarks.html")
27 freenetRequest.isPOST -> {
28 freenetRequest.parameters["post", 36]
29 ?.let(webInterface.core::getPost)
30 ?.also(webInterface.core::unbookmarkPost)
31 throw RedirectException(freenetRequest.parameters["returnPage", 256])