🚧 Add handler for image-insert notifications
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / CreateReplyAjaxPage.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  * This AJAX page create a reply.
12  */
13 @ToadletPath("createReply.ajax")
14 class CreateReplyAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
15
16         override fun createJsonObject(currentSone: Sone, request: FreenetRequest): JsonReturnObject =
17                         request.parameters["post"].emptyToNull
18                                         ?.let(core::getPost)
19                                         ?.let { post ->
20                                                 val text = TextFilter.filter(request.headers["Host"], request.parameters["text"])
21                                                 val sender = request.parameters["sender"].let(core::getLocalSone) ?: currentSone
22                                                 val reply = core.createReply(sender, post, text)
23                                                 createSuccessJsonObject().apply {
24                                                         put("reply", reply.id)
25                                                         put("sone", sender.id)
26                                                 }
27                                         }
28                                         ?: createErrorJsonObject("invalid-post-id")
29
30 }