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.*
8 import javax.inject.Inject
11 * AJAX page that lets the user dismiss a notification.
13 @ToadletPath("dismissNotification.ajax")
14 class DismissNotificationAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
16 override val requiresLogin = false
18 override fun createJsonObject(request: FreenetRequest): JsonReturnObject =
19 request.parameters["notification"]!!
20 .let(webInterface::getNotification)
21 .let { notification ->
22 notification.isDismissable.ifTrue {
23 createSuccessJsonObject().also {
24 notification.dismiss()
26 } ?: createErrorJsonObject("not-dismissable")
27 } ?: createErrorJsonObject("invalid-notification-id")