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=3b206c8c47e3c0465422b21235e1048c5d64ae28;hb=ea7ad5e87074576d17b7df74365a726bd95d7665;hpb=d142608024302ca4106a70b95daabf27aa5362a4 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 3b206c8..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,28 +1,29 @@ 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(webInterface.core::getPost) + ?.let(core::getPost) ?.let { currentSone.addLikedPostId(it.id) } - ?.also { webInterface.core.touchConfiguration() } + ?.also { core.touchConfiguration() } ?.let { createSuccessJsonObject() } ?: createErrorJsonObject("invalid-post-id") "reply" -> request.parameters["reply"] - .let(webInterface.core::getPostReply) + ?.let(core::getPostReply) ?.let { currentSone.addLikedReplyId(it.id) } - ?.also { webInterface.core.touchConfiguration() } + ?.also { core.touchConfiguration() } ?.let { createSuccessJsonObject() } ?: createErrorJsonObject("invalid-reply-id") else -> createErrorJsonObject("invalid-type")