🔥 Remove deprecated methods
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / CreatePostAjaxPage.kt
1 package net.pterodactylus.sone.web.ajax
2
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.*
8 import javax.inject.*
9
10 /**
11  * AJAX handler that creates a new post.
12  */
13 @ToadletPath("createPost.ajax")
14 class CreatePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
15
16         override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
17                         request.parameters["text"].emptyToNull
18                                         ?.let { TextFilter.filter(request.headers["Host"], it) }
19                                         ?.let { text ->
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.asOptional(), text).let { post ->
23                                                         createSuccessJsonObject().apply {
24                                                                 put("postId", post.id)
25                                                                 put("sone", sender.id)
26                                                                 put("recipient", recipient?.id)
27                                                         }
28                                                 }
29                                         } ?: createErrorJsonObject("text-required")
30
31 }