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 net.pterodactylus.util.template.TemplateContextFactory
import java.io.StringWriter
import javax.inject.Inject
/**
* AJAX handler to return all current notifications.
*/
-class GetNotificationsAjaxPage @Inject constructor(webInterface: WebInterface) :
- JsonPage("getNotifications.ajax", webInterface) {
+@ToadletPath("getNotifications.ajax")
+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 ->
)
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
"ShowNotification/NewReplies" to options.isShowNewReplyNotifications
)
} ?: jsonObject {}
-
-private fun Notification.render() = StringWriter().use { it.also { render(it) } }.toString()