Move web pages to their own package
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DismissNotificationPage.kt
diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt
new file mode 100644 (file)
index 0000000..6e8a3d2
--- /dev/null
@@ -0,0 +1,22 @@
+package net.pterodactylus.sone.web.pages
+
+import net.pterodactylus.sone.web.pages.SoneTemplatePage
+import net.pterodactylus.sone.web.WebInterface
+import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.util.template.Template
+import net.pterodactylus.util.template.TemplateContext
+
+/**
+ * Page that lets the user dismiss a notification.
+ */
+class DismissNotificationPage(template: Template, webInterface: WebInterface):
+               SoneTemplatePage("dismissNotification.html", template, "Page.DismissNotification.Title", webInterface) {
+
+       override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
+               val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256)
+               val notificationId = request.httpRequest.getPartAsStringFailsafe("notification", 36)
+               webInterface.getNotification(notificationId).orNull()?.takeIf { it.isDismissable }?.dismiss()
+               throw RedirectException(returnPage)
+       }
+
+}