♻️ Add freenet client interface
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / UnbookmarkPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.utils.*
6 import net.pterodactylus.sone.web.*
7 import net.pterodactylus.sone.web.page.*
8 import net.pterodactylus.util.template.*
9 import javax.inject.*
10
11 /**
12  * Page that lets the user unbookmark a post.
13  */
14 @ToadletPath("unbookmark.html")
15 class UnbookmarkPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
16                 SoneTemplatePage(webInterface, loaders, templateRenderer, pageTitleKey = "Page.Unbookmark.Title") {
17
18         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
19                 when {
20                         soneRequest.isGET && (soneRequest.parameters["post"] == "allNotLoaded") -> {
21                                 soneRequest.core.bookmarkedPosts
22                                                 .filterNot(Post::isLoaded)
23                                                 .forEach(soneRequest.core::unbookmarkPost)
24                                 redirectTo("bookmarks.html")
25                         }
26                         soneRequest.isPOST -> {
27                                 soneRequest.parameters["post", 36]
28                                                 ?.let(soneRequest.core::getPost)
29                                                 ?.also(soneRequest.core::unbookmarkPost)
30                                 redirectTo(soneRequest.parameters["returnPage", 256])
31                         }
32                 }
33         }
34
35 }