Replace get notifications ajax page with Kotlin version
[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.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
11 /**
12  * Page that lets the user mark a number of [net.pterodactylus.sone.data.Sone]s, [Post]s, or
13  * [Replie][net.pterodactylus.sone.data.Reply]s as known.
14  */
15 class MarkAsKnownPage(template: Template, webInterface: WebInterface):
16                 SoneTemplatePage("markAsKnown.html", template, "Page.MarkAsKnown.Title", webInterface, false) {
17
18         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
19                 val ids = request.parameters["id", 65536]!!.split(" ")
20                 when (request.parameters["type", 5]) {
21                         "sone" -> ids.mapPresent(webInterface.core::getSone).forEach(webInterface.core::markSoneKnown)
22                         "post" -> ids.mapPresent(webInterface.core::getPost).forEach(webInterface.core::markPostKnown)
23                         "reply" -> ids.mapPresent(webInterface.core::getPostReply).forEach(webInterface.core::markReplyKnown)
24                         else -> throw RedirectException("invalid.html")
25                 }
26                 throw RedirectException(request.parameters["returnPage", 256]!!)
27         }
28
29 }