Replace distrust ajax page with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / DistrustAjaxPage.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.core.Core
4 import net.pterodactylus.sone.utils.let
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8
9 /**
10  * AJAX page that lets the user distrust a Sone.
11  *
12  * @see Core.distrustSone(Sone, Sone)
13  */
14 class DistrustAjaxPage(webInterface: WebInterface) : JsonPage("distrustSone.ajax", webInterface) {
15
16         override fun createJsonObject(request: FreenetRequest) =
17                         request.parameters["sone"]
18                                         .let(webInterface.core::getSone)
19                                         ?.let { sone ->
20                                                 createSuccessJsonObject()
21                                                                 .put("trustValue", webInterface.core.preferences.negativeTrust)
22                                                                 .also {
23                                                                         webInterface.core.distrustSone(getCurrentSone(request.toadletContext), sone)
24                                                                 }
25                                         } ?: createErrorJsonObject("invalid-sone-id")
26
27 }