🚧 Add event for first start of Sone
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / DeletePostAjaxPage.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.utils.*
5 import net.pterodactylus.sone.web.*
6 import net.pterodactylus.sone.web.page.*
7 import javax.inject.*
8
9 /**
10  * This AJAX page deletes a post.
11  */
12 @ToadletPath("deletePost.ajax")
13 class DeletePostAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
14
15         override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
16                         request.parameters["post"]
17                                         ?.let(core::getPost)
18                                         ?.let { post ->
19                                                 post.sone.isLocal.ifTrue {
20                                                         createSuccessJsonObject().also {
21                                                                 core.deletePost(post)
22                                                         }
23                                                 } ?: createErrorJsonObject("not-authorized")
24                                         } ?: createErrorJsonObject("invalid-post-id")
25
26 }