Use method from JsonPage
[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.data.Sone
5 import net.pterodactylus.sone.utils.let
6 import net.pterodactylus.sone.utils.parameters
7 import net.pterodactylus.sone.web.WebInterface
8 import net.pterodactylus.sone.web.page.FreenetRequest
9
10 /**
11  * AJAX page that lets the user distrust a Sone.
12  *
13  * @see Core.distrustSone(Sone, Sone)
14  */
15 class DistrustAjaxPage(webInterface: WebInterface) : LoggedInJsonPage("distrustSone.ajax", webInterface) {
16
17         override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
18                         request.parameters["sone"]
19                                         .let(webInterface.core::getSone)
20                                         ?.let { sone ->
21                                                 createSuccessJsonObject()
22                                                                 .put("trustValue", webInterface.core.preferences.negativeTrust)
23                                                                 .also {
24                                                                         webInterface.core.distrustSone(currentSone, sone)
25                                                                 }
26                                         } ?: createErrorJsonObject("invalid-sone-id")
27
28 }