Replace Sone provider interface with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / GetStatusAjaxPage.kt
index 853fe26..7646704 100644 (file)
@@ -12,6 +12,7 @@ import net.pterodactylus.sone.freenet.L10nFilter
 import net.pterodactylus.sone.template.SoneAccessor
 import net.pterodactylus.sone.text.TimeTextConverter
 import net.pterodactylus.sone.utils.jsonObject
+import net.pterodactylus.sone.utils.mapPresent
 import net.pterodactylus.sone.utils.toArray
 import net.pterodactylus.sone.web.WebInterface
 import net.pterodactylus.sone.web.page.FreenetRequest
@@ -30,12 +31,12 @@ class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: E
        }
 
        override fun createJsonObject(request: FreenetRequest) =
-                       webInterface.getCurrentSoneWithoutCreatingSession(request.toadletContext).let { currentSone ->
+                       getCurrentSone(request.toadletContext, false).let { currentSone ->
                                createSuccessJsonObject().apply {
                                        this["loggedIn"] = currentSone != null
                                        this["options"] = currentSone?.options?.toJsonOptions() ?: jsonObject {}
                                        this["notificationHash"] = webInterface.getNotifications(currentSone).sortedBy { it.createdTime }.hashCode()
-                                       this["sones"] = request.httpRequest.getParam("soneIds").split(',').map { webInterface.core.getSone(it).orNull() }.plus(currentSone).filterNotNull().toJsonSones()
+                                       this["sones"] = request.httpRequest.getParam("soneIds").split(',').mapNotNull(core::getSone).plus(currentSone).filterNotNull().toJsonSones()
                                        this["newPosts"] = webInterface.getNewPosts(currentSone).toJsonPosts()
                                        this["newReplies"] = webInterface.getNewReplies(currentSone).toJsonReplies()
                                        this["linkedElements"] = request.httpRequest.getParam("elements", "[]").asJson().map(JsonNode::asText).map(elementLoader::loadElement).toJsonElements()
@@ -48,8 +49,8 @@ class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: E
 
        private fun String.asJson() = ObjectMapper().readTree(this).asIterable()
 
-       override fun needsFormPassword() = false
-       override fun requiresLogin() = false
+       override val needsFormPassword = false
+       override val requiresLogin = false
 
        private fun SoneOptions.toJsonOptions() = jsonObject {
                put("ShowNotification/NewSones", isShowNewSoneNotifications)
@@ -63,8 +64,8 @@ class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: E
                        put("name", SoneAccessor.getNiceName(sone))
                        put("local", sone.isLocal)
                        put("status", sone.status.name)
-                       put("modified", webInterface.core.isModifiedSone(sone))
-                       put("locked", webInterface.core.isLocked(sone))
+                       put("modified", core.isModifiedSone(sone))
+                       put("locked", core.isLocked(sone))
                        put("lastUpdatedUnknown", sone.time == 0L)
                        synchronized(dateFormatter) {
                                put("lastUpdated", dateFormatter.format(sone.time))