X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetNotificationsAjaxPage.kt;h=66c8ed2dce6b6d3b7a139fcd269683a12ad9564e;hb=4c5ec477a0f12a4cee0143636fe015e83eec5060;hp=d218a3df7452f014c1c80367c49b4549d71232d1;hpb=2a202f56661ecbfb1be46066a1df7c4dad3042e3;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt index d218a3d..66c8ed2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt @@ -3,21 +3,22 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.data.SoneOptions import net.pterodactylus.sone.main.SonePlugin -import net.pterodactylus.sone.utils.jsonArray -import net.pterodactylus.sone.utils.jsonObject +import net.pterodactylus.sone.utils.* import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import net.pterodactylus.util.notify.Notification import net.pterodactylus.util.notify.TemplateNotification import java.io.StringWriter +import javax.inject.Inject /** * AJAX handler to return all current notifications. */ -class GetNotificationsAjaxPage(webInterface: WebInterface) : JsonPage("getNotifications.ajax", webInterface) { +@ToadletPath("getNotifications.ajax") +class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { - override fun needsFormPassword() = false - override fun requiresLogin() = false + override val needsFormPassword = false + override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = getCurrentSone(request.toadletContext, false).let { currentSone -> @@ -48,15 +49,15 @@ class GetNotificationsAjaxPage(webInterface: WebInterface) : JsonPage("getNotifi val mergedTemplateContext = webInterface.templateContextFactory.createTemplateContext() .mergeContext(templateContext) .apply { - this["core"] = webInterface.core + this["core"] = core this["currentSone"] = currentSone - this["localSones"] = webInterface.core.localSones + this["localSones"] = core.localSones this["request"] = freenetRequest this["currentVersion"] = SonePlugin.getPluginVersion() - this["hasLatestVersion"] = webInterface.core.updateChecker.hasLatestVersion() - this["latestEdition"] = webInterface.core.updateChecker.latestEdition - this["latestVersion"] = webInterface.core.updateChecker.latestVersion - this["latestVersionTime"] = webInterface.core.updateChecker.latestVersionDate + this["hasLatestVersion"] = core.updateChecker.hasLatestVersion() + this["latestEdition"] = core.updateChecker.latestEdition + this["latestVersion"] = core.updateChecker.latestVersion + this["latestVersionTime"] = core.updateChecker.latestVersionDate this["notification"] = this@render } it.also { render(mergedTemplateContext, it) } @@ -72,5 +73,3 @@ private val SoneOptions?.asJsonObject "ShowNotification/NewReplies" to options.isShowNewReplyNotifications ) } ?: jsonObject {} - -private fun Notification.render() = StringWriter().use { it.also { render(it) } }.toString()