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.*
6 import javax.inject.Inject
9 * AJAX page that lets the user mark a number of [net.pterodactylus.sone.data.Sone]s,
10 * [net.pterodactylus.sone.data.Post]s, or [net.pterodactylus.sone.data.Reply]s as known.
12 @ToadletPath("markAsKnown.ajax")
13 class MarkAsKnownAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
15 override val requiresLogin = false
17 override fun createJsonObject(request: FreenetRequest) = when (request.parameters["type"]) {
18 "sone" -> processIds(request, core::getSone, core::markSoneKnown)
19 "post" -> processIds(request, core::getPost, core::markPostKnown)
20 "reply" -> processIds(request, core::getPostReply, core::markReplyKnown)
21 else -> createErrorJsonObject("invalid-type")
24 private fun <T : Any> processIds(request: FreenetRequest, getter: (String) -> T?, marker: (T) -> Unit) =
25 request.parameters["id"]
29 .let { createSuccessJsonObject() }