X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetNotificationsAjaxPage.kt;h=adf3e26b8ed6218136eae7011c6ce3bb12c528f6;hb=bf509980d5097e67d1a32f6b53bef052b396137f;hp=db6e5c5f8a411895a26216aea8a92b778ce5cb6c;hpb=03cec6a6772c2d836d94864adddaf544cbe9d72f;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 db6e5c5..adf3e26 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.kt @@ -3,12 +3,12 @@ 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.* import net.pterodactylus.util.notify.Notification import net.pterodactylus.util.notify.TemplateNotification +import net.pterodactylus.util.template.TemplateContextFactory import java.io.StringWriter import javax.inject.Inject @@ -16,13 +16,13 @@ import javax.inject.Inject * AJAX handler to return all current notifications. */ @ToadletPath("getNotifications.ajax") -class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface) : JsonPage(webInterface) { +class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface, private val templateContextFactory: TemplateContextFactory) : JsonPage(webInterface) { override val needsFormPassword = false override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = - getCurrentSone(request.toadletContext, false).let { currentSone -> + getCurrentSone(request.toadletContext).let { currentSone -> webInterface.getNotifications(currentSone) .sortedBy(Notification::getCreatedTime) .let { notifications -> @@ -47,7 +47,7 @@ class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface) : ) private fun TemplateNotification.render(currentSone: Sone?, freenetRequest: FreenetRequest) = StringWriter().use { - val mergedTemplateContext = webInterface.templateContextFactory.createTemplateContext() + val mergedTemplateContext = templateContextFactory.createTemplateContext() .mergeContext(templateContext) .apply { this["core"] = core @@ -74,5 +74,3 @@ private val SoneOptions?.asJsonObject "ShowNotification/NewReplies" to options.isShowNewReplyNotifications ) } ?: jsonObject {} - -private fun Notification.render() = StringWriter().use { it.also { render(it) } }.toString()