X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetStatusAjaxPage.kt;h=19cd7f984a3e9209e0a0982cb3630f3a64aba86f;hb=4965986ea98879fbe0a2ca9bcf8dbeeeaebaa9ef;hp=0017a32489b0fa24398bb6a95872fa94757e7f09;hpb=9021ef622e01f71f067cab0583ac849b98646e16;p=Sone.git 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 0017a32..19cd7f9 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.kt @@ -13,8 +13,9 @@ import net.pterodactylus.sone.template.SoneAccessor import net.pterodactylus.sone.text.TimeTextConverter import net.pterodactylus.sone.utils.jsonObject import net.pterodactylus.sone.utils.toArray +import net.pterodactylus.sone.web.NewElements 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 @@ -23,25 +24,28 @@ 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, timeZone: TimeZone): - JsonPage("getStatus.ajax", webInterface) { +@ToadletPath("getStatus.ajax") +class GetStatusAjaxPage(webInterface: WebInterface, private val elementLoader: ElementLoader, private val newElements: NewElements, private val timeTextConverter: TimeTextConverter, private val l10nFilter: L10nFilter, timeZone: TimeZone): + JsonPage(webInterface) { - @Inject constructor(webInterface: WebInterface, elementLoader: ElementLoader, timeTextConverter: TimeTextConverter, l10nFilter: L10nFilter): - this(webInterface, elementLoader, timeTextConverter, l10nFilter, TimeZone.getDefault()) + @Inject constructor(webInterface: WebInterface, elementLoader: ElementLoader, newElements: NewElements, timeTextConverter: TimeTextConverter, l10nFilter: L10nFilter): + this(webInterface, elementLoader, newElements, timeTextConverter, l10nFilter, TimeZone.getDefault()) - private val dateFormatter = SimpleDateFormat("MMM d, yyyy, HH:mm:ss").apply { - this.timeZone = timeZone + private val dateFormatter by lazy { + SimpleDateFormat("MMM d, yyyy, HH:mm:ss").apply { + this.timeZone = timeZone + } } override fun createJsonObject(request: FreenetRequest) = - getCurrentSone(request.toadletContext, false).let { currentSone -> + getCurrentSone(request.toadletContext).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(',').mapNotNull(core::getSone).plus(currentSone).filterNotNull().toJsonSones() - this["newPosts"] = webInterface.getNewPosts(currentSone).toJsonPosts() - this["newReplies"] = webInterface.getNewReplies(currentSone).toJsonReplies() + this["newPosts"] = newElements.newPosts.toJsonPosts() + this["newReplies"] = newElements.newReplies.toJsonReplies() this["linkedElements"] = request.httpRequest.getParam("elements", "[]").asJson().map(JsonNode::asText).map(elementLoader::loadElement).toJsonElements() } }