1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.utils.parameters
4 import net.pterodactylus.sone.web.WebInterface
5 import net.pterodactylus.sone.web.page.FreenetRequest
8 * AJAX page that lets the user mark a number of [net.pterodactylus.sone.data.Sone]s,
9 * [net.pterodactylus.sone.data.Post]s, or [net.pterodactylus.sone.data.Reply]s as known.
11 class MarkAsKnownAjaxPage(webInterface: WebInterface) : JsonPage("markAsKnown.ajax", webInterface) {
13 override val requiresLogin = false
15 override fun createJsonObject(request: FreenetRequest) = when (request.parameters["type"]) {
16 "sone" -> processIds(request, core::getSone, core::markSoneKnown)
17 "post" -> processIds(request, core::getPost, core::markPostKnown)
18 "reply" -> processIds(request, core::getPostReply, core::markReplyKnown)
19 else -> createErrorJsonObject("invalid-type")
22 private fun <T : Any> processIds(request: FreenetRequest, getter: (String) -> T?, marker: (T) -> Unit) =
23 request.parameters["id"]
27 .let { createSuccessJsonObject() }