✨ Use new template renderer
[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.main.*
4 import net.pterodactylus.sone.web.WebInterface
5 import net.pterodactylus.sone.web.page.*
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
8 import javax.inject.Inject
9
10 /**
11  * Page that lets the user dismiss a notification.
12  */
13 class DismissNotificationPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
14                 SoneTemplatePage("dismissNotification.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.DismissNotification.Title") {
15
16         override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
17                 val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)
18                 val notificationId = soneRequest.httpRequest.getPartAsStringFailsafe("notification", 36)
19                 soneRequest.webInterface.getNotification(notificationId).orNull()?.takeIf { it.isDismissable }?.dismiss()
20                 throw RedirectException(returnPage)
21         }
22
23 }