X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FTrustAjaxPage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FTrustAjaxPage.kt;h=228a0b5a946dcfadc270f036404ffb0982def514;hp=0000000000000000000000000000000000000000;hb=434e72844bb54f24fc7d2d26acc315d39ee3ba6f;hpb=0e49fb05ba0c23c25d51b4c7584e35e2b923061b diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt new file mode 100644 index 0000000..228a0b5 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt @@ -0,0 +1,23 @@ +package net.pterodactylus.sone.web.ajax + +import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.utils.let +import net.pterodactylus.sone.utils.parameters +import net.pterodactylus.sone.web.WebInterface +import net.pterodactylus.sone.web.page.FreenetRequest + +/** + * AJAX page that lets the user trust a Sone. + * + * @see net.pterodactylus.sone.core.Core.trustSone + */ +class TrustAjaxPage(webInterface: WebInterface) : LoggedInJsonPage("trustSone.ajax", webInterface) { + + override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = + request.parameters["sone"] + .let(webInterface.core::getSone) + ?.let { webInterface.core.trustSone(currentSone, it) } + ?.let { createSuccessJsonObject().put("trustValue", webInterface.core.preferences.positiveTrust) } + ?: createErrorJsonObject("invalid-sone-id") + +}