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