Use method from JsonPage
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / DismissNotificationAjaxPage.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.utils.ifTrue
4 import net.pterodactylus.sone.utils.let
5 import net.pterodactylus.sone.utils.parameters
6 import net.pterodactylus.sone.web.WebInterface
7 import net.pterodactylus.sone.web.page.FreenetRequest
8
9 /**
10  * AJAX page that lets the user dismiss a notification.
11  */
12 class DismissNotificationAjaxPage(webInterface: WebInterface) : JsonPage("dismissNotification.ajax", webInterface) {
13
14         override fun requiresLogin() = false
15
16         override fun createJsonObject(request: FreenetRequest): JsonReturnObject =
17                         request.parameters["notification"]!!
18                                         .let(webInterface::getNotification)
19                                         .let { notification ->
20                                                 notification.isDismissable.ifTrue {
21                                                         createSuccessJsonObject().also {
22                                                                 notification.dismiss()
23                                                         }
24                                                 } ?: createErrorJsonObject("not-dismissable")
25                                         } ?: createErrorJsonObject("invalid-notification-id")
26
27 }