1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.utils.mapPresent
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8 import net.pterodactylus.util.template.Template
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
13 * Page that lets the user mark a number of [net.pterodactylus.sone.data.Sone]s, [Post]s, or
14 * [Replie][net.pterodactylus.sone.data.Reply]s as known.
16 class MarkAsKnownPage @Inject constructor(template: Template, webInterface: WebInterface):
17 SoneTemplatePage("markAsKnown.html", webInterface, template, "Page.MarkAsKnown.Title") {
19 override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) {
20 val ids = freenetRequest.parameters["id", 65536]!!.split(" ")
21 when (freenetRequest.parameters["type", 5]) {
22 "sone" -> ids.mapNotNull(webInterface.core::getSone).forEach(webInterface.core::markSoneKnown)
23 "post" -> ids.mapNotNull(webInterface.core::getPost).forEach(webInterface.core::markPostKnown)
24 "reply" -> ids.mapNotNull(webInterface.core::getPostReply).forEach(webInterface.core::markReplyKnown)
25 else -> throw RedirectException("invalid.html")
27 throw RedirectException(freenetRequest.parameters["returnPage", 256]!!)