X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetStatusAjaxPage.kt;h=75f3c3c7a7b19f3a8b7e28f3379bac6bf88f0810;hp=d7884bf31f70c60ffea48786af590ecba0f5624b;hb=ca45de0dcbd2e361ab630bbee1d47ff6cf34d97c;hpb=dd96e781b592c3bae9b0f66f85ba05a4e4cc18ce diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt index d7884bf..75f3c3c 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt @@ -14,28 +14,36 @@ import net.pterodactylus.sone.text.TimeTextConverter import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.utils.toArray import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* import java.text.SimpleDateFormat +import java.util.TimeZone +import javax.inject.Inject /** * 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): - JsonPage("getStatus.ajax", webInterface) { +@ToadletPath("getStatus.ajax") +class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter, timeZone: TimeZone): + JsonPage(webInterface) { - private val dateFormatter = SimpleDateFormat("MMM d, yyyy, HH:mm:ss") + @Inject constructor(webInterface: WebInterface, elementLoader: ElementLoader, timeTextConverter: TimeTextConverter, l10nFilter: L10nFilter): + this(webInterface, elementLoader, timeTextConverter, l10nFilter, TimeZone.getDefault()) + + 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 -> + 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["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() } } @@ -45,8 +53,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) @@ -60,8 +68,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))