1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.text.*
5 import net.pterodactylus.sone.utils.*
6 import net.pterodactylus.sone.web.*
7 import net.pterodactylus.sone.web.page.*
11 * AJAX handler that creates a new post.
13 @ToadletPath("createPost.ajax")
14 class CreatePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
16 override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
17 request.parameters["text"].emptyToNull
18 ?.let { TextFilter.filter(request.headers["Host"], it) }
20 val sender = request.parameters["sender"].emptyToNull?.let(core::getSone) ?: currentSone
21 val recipient = request.parameters["recipient"]?.let(core::getSone)
22 core.createPost(sender, recipient, text).let { post ->
23 createSuccessJsonObject().apply {
24 put("postId", post.id)
25 put("sone", sender.id)
26 put("recipient", recipient?.id)
29 } ?: createErrorJsonObject("text-required")