🚧 Change rescheduling method
[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.*
8 import javax.inject.Inject
9
10 /**
11  * AJAX page that lets the user dismiss a notification.
12  */
13 @ToadletPath("dismissNotification.ajax")
14 class DismissNotificationAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) {
15
16         override val requiresLogin = false
17
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()
25                                                         }
26                                                 } ?: createErrorJsonObject("not-dismissable")
27                                         } ?: createErrorJsonObject("invalid-notification-id")
28
29 }