1 package net.pterodactylus.sone.web.ajax
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
10 * AJAX page that lets the user dismiss a notification.
12 class DismissNotificationAjaxPage(webInterface: WebInterface) : JsonPage("dismissNotification.ajax", webInterface) {
14 override fun requiresLogin() = false
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()
24 } ?: createErrorJsonObject("not-dismissable")
25 } ?: createErrorJsonObject("invalid-notification-id")