Add base JSON page that requires a logged-in user
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / ajax / GetStatusAjaxPage.kt
index d7884bf..853fe26 100644 (file)
@@ -16,18 +16,21 @@ import net.pterodactylus.sone.utils.toArray
 import net.pterodactylus.sone.web.WebInterface
 import net.pterodactylus.sone.web.page.FreenetRequest
 import java.text.SimpleDateFormat
+import java.util.TimeZone
 
 /**
  * The “get status” AJAX handler returns all information that is necessary to
  * update the web interface in real-time.
  */
-class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter):
+class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter, timeZone: TimeZone = TimeZone.getDefault()):
                JsonPage("getStatus.ajax", webInterface) {
 
-       private val dateFormatter = SimpleDateFormat("MMM d, yyyy, HH:mm:ss")
+       private val dateFormatter = SimpleDateFormat("MMM d, yyyy, HH:mm:ss").apply {
+               this.timeZone = timeZone
+       }
 
        override fun createJsonObject(request: FreenetRequest) =
-                       (webInterface.getCurrentSoneWithoutCreatingSession(request.toadletContext) as Sone?).let { currentSone ->
+                       webInterface.getCurrentSoneWithoutCreatingSession(request.toadletContext).let { currentSone ->
                                createSuccessJsonObject().apply {
                                        this["loggedIn"] = currentSone != null
                                        this["options"] = currentSone?.options?.toJsonOptions() ?: jsonObject {}
@@ -35,7 +38,7 @@ class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: E
                                        this["sones"] = request.httpRequest.getParam("soneIds").split(',').map { webInterface.core.getSone(it).orNull() }.plus(currentSone).filterNotNull().toJsonSones()
                                        this["newPosts"] = webInterface.getNewPosts(currentSone).toJsonPosts()
                                        this["newReplies"] = webInterface.getNewReplies(currentSone).toJsonReplies()
-                                       this["loadedElements"] = request.httpRequest.getParam("elements", "[]").asJson().map(JsonNode::asText).map(elementLoader::loadElement).toJsonElements()
+                                       this["linkedElements"] = request.httpRequest.getParam("elements", "[]").asJson().map(JsonNode::asText).map(elementLoader::loadElement).toJsonElements()
                                }
                        }