ae0cfe0291f7be0fa528d7bd850d3d68bfb4394d
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DismissNotificationPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.web.WebInterface
4 import net.pterodactylus.sone.web.page.*
5 import net.pterodactylus.util.template.Template
6 import net.pterodactylus.util.template.TemplateContext
7 import javax.inject.Inject
8
9 /**
10  * Page that lets the user dismiss a notification.
11  */
12 class DismissNotificationPage @Inject constructor(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("dismissNotification.html", webInterface, template, "Page.DismissNotification.Title") {
14
15         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
16                 val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
17                 val notificationId = soneRequest.httpRequest.getPartAsStringFailsafe("notification", 36)
18                 soneRequest.webInterface.getNotification(notificationId).orNull()?.takeIf { it.isDismissable }?.dismiss()
19                 throw RedirectException(returnPage)
20         }
21
22 }