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