0c37ac0239667306b093cd0c09827a743ec7c225
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / FollowSoneAjaxPage.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.utils.also
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 a Sone follow another Sone.
12  */
13 class FollowSoneAjaxPage(webInterface: WebInterface) : LoggedInJsonPage("followSone.ajax", webInterface) {
14
15         override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
16                         request.parameters["sone"]
17                                         ?.let(core::getSone)
18                                         ?.also { core.followSone(currentSone, it.id) }
19                                         ?.also(core::markSoneKnown)
20                                         ?.let { createSuccessJsonObject() }
21                                         ?: createErrorJsonObject("invalid-sone-id")
22
23 }