6e8a3d2d6192783d36208dd13c70c6546a0692ec
[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.pages.SoneTemplatePage
4 import net.pterodactylus.sone.web.WebInterface
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
8
9 /**
10  * Page that lets the user dismiss a notification.
11  */
12 class DismissNotificationPage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("dismissNotification.html", template, "Page.DismissNotification.Title", webInterface) {
14
15         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
16                 val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
17                 val notificationId = request.httpRequest.getPartAsStringFailsafe("notification", 36)
18                 webInterface.getNotification(notificationId).orNull()?.takeIf { it.isDismissable }?.dismiss()
19                 throw RedirectException(returnPage)
20         }
21
22 }