X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FLikeAjaxPage.kt;h=fe52c9d234289d5f73a4236f881b4ad3291b4eac;hp=4257725f5cc38cf815f4d996ac296da6dd7b9ccc;hb=ea7ad5e87074576d17b7df74365a726bd95d7665;hpb=ffd92ca2374c0b2218e583d02e0bdd24b8c110ae diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt index 4257725..fe52c9d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/LikeAjaxPage.kt @@ -1,26 +1,27 @@ 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 +import javax.inject.Inject /** * AJAX page that lets the user like a [net.pterodactylus.sone.data.Post]. */ -class LikeAjaxPage(webInterface: WebInterface) : LoggedInJsonPage("like.ajax", webInterface) { +class LikeAjaxPage @Inject constructor(webInterface: WebInterface) : + LoggedInJsonPage("like.ajax", webInterface) { override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = when (request.parameters["type"]) { "post" -> request.parameters["post"] - .let(core::getPost) + ?.let(core::getPost) ?.let { currentSone.addLikedPostId(it.id) } ?.also { core.touchConfiguration() } ?.let { createSuccessJsonObject() } ?: createErrorJsonObject("invalid-post-id") "reply" -> request.parameters["reply"] - .let(core::getPostReply) + ?.let(core::getPostReply) ?.let { currentSone.addLikedReplyId(it.id) } ?.also { core.touchConfiguration() } ?.let { createSuccessJsonObject() }