override fun createJsonObject(request: FreenetRequest) =
request.parameters["post"].emptyToNull
- ?.let(webInterface.core::getPost)
- ?.also(webInterface.core::bookmarkPost)
+ ?.let(core::getPost)
+ ?.also(core::bookmarkPost)
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-post-id")
request.parameters["text"].emptyToNull
?.let { TextFilter.filter(request.headers["Host"], it) }
?.let { text ->
- val sender = request.parameters["sender"].emptyToNull?.let(webInterface.core::getSone)?.orNull() ?: currentSone
- val recipient = request.parameters["recipient"].let(webInterface.core::getSone)
- webInterface.core.createPost(sender, recipient, text).let { post ->
+ val sender = request.parameters["sender"].emptyToNull?.let(core::getSone)?.orNull() ?: currentSone
+ val recipient = request.parameters["recipient"].let(core::getSone)
+ core.createPost(sender, recipient, text).let { post ->
createSuccessJsonObject().apply {
put("postId", post.id)
put("sone", sender.id)
override fun createJsonObject(currentSone: Sone, request: FreenetRequest): JsonReturnObject =
request.parameters["post"].emptyToNull
- ?.let(webInterface.core::getPost)
+ ?.let(core::getPost)
?.let { post ->
val text = TextFilter.filter(request.headers["Host"], request.parameters["text"])
- val sender = request.parameters["sender"].let(webInterface.core::getLocalSone) ?: currentSone
- val reply = webInterface.core.createReply(sender, post, text)
+ val sender = request.parameters["sender"].let(core::getLocalSone) ?: currentSone
+ val reply = core.createReply(sender, post, text)
createSuccessJsonObject().apply {
put("reply", reply.id)
put("sone", sender.id)
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["post"]
- .let(webInterface.core::getPost)
+ .let(core::getPost)
?.let { post ->
post.sone.isLocal.ifTrue {
createSuccessJsonObject().also {
- webInterface.core.deletePost(post)
+ core.deletePost(post)
}
} ?: createErrorJsonObject("not-authorized")
} ?: createErrorJsonObject("invalid-post-id")
createSuccessJsonObject().also {
profile.removeField(field)
currentSone.profile = profile
- webInterface.core.touchConfiguration()
+ core.touchConfiguration()
}
} ?: createErrorJsonObject("invalid-field-id")
}
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["reply"]
- .let(webInterface.core::getPostReply)
+ .let(core::getPostReply)
?.let { reply ->
reply.sone.isLocal.ifTrue {
createSuccessJsonObject().also {
- webInterface.core.deleteReply(reply)
+ core.deleteReply(reply)
}
} ?: createErrorJsonObject("not-authorized")
} ?: createErrorJsonObject("invalid-reply-id")
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
- .let(webInterface.core::getSone)
+ .let(core::getSone)
?.let { sone ->
createSuccessJsonObject()
- .put("trustValue", webInterface.core.preferences.negativeTrust)
+ .put("trustValue", core.preferences.negativeTrust)
.also {
- webInterface.core.distrustSone(currentSone, sone)
+ core.distrustSone(currentSone, sone)
}
} ?: createErrorJsonObject("invalid-sone-id")
override fun createJsonObject(request: FreenetRequest) =
request.parameters["album"]!!
- .let(webInterface.core::getAlbum)
+ .let(core::getAlbum)
?.let { album ->
album.sone.isLocal.ifTrue {
when {
override fun createJsonObject(request: FreenetRequest) =
request.parameters["image"]
- .let(webInterface.core::getImage)
+ .let(core::getImage)
?.let { image ->
image.sone.isLocal.ifTrue {
when {
request.parameters["moveLeft"] == "true" -> createSuccessJsonObject().apply {
put("sourceImageId", image.id)
put("destinationImageId", image.album.moveImageUp(image).id)
- webInterface.core.touchConfiguration()
+ core.touchConfiguration()
}
request.parameters["moveRight"] == "true" -> createSuccessJsonObject().apply {
put("sourceImageId", image.id)
put("destinationImageId", image.album.moveImageDown(image).id)
- webInterface.core.touchConfiguration()
+ core.touchConfiguration()
}
else -> request.parameters["title"]!!.let { title ->
title.trim().isNotBlank().ifTrue {
}
}
})
- webInterface.core.touchConfiguration()
+ core.touchConfiguration()
}
}
}
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
- .let(webInterface.core::getSone)
- ?.also { webInterface.core.followSone(currentSone, it.id) }
- ?.also(webInterface.core::markSoneKnown)
+ .let(core::getSone)
+ ?.also { core.followSone(currentSone, it.id) }
+ ?.also(core::markSoneKnown)
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-sone-id")
override fun createJsonObject(request: FreenetRequest) =
when (request.parameters["type"]) {
"post" -> request.parameters["post"]
- .let(webInterface.core::getPost)
- ?.let(webInterface.core::getLikes)
+ .let(core::getPost)
+ ?.let(core::getLikes)
?.toReply()
?: createErrorJsonObject("invalid-post-id")
"reply" -> request.parameters["reply"]
- .let(webInterface.core::getPostReply)
- ?.let(webInterface.core::getLikes)
+ .let(core::getPostReply)
+ ?.let(core::getLikes)
?.toReply()
?: createErrorJsonObject("invalid-reply-id")
else -> createErrorJsonObject("invalid-type")
val mergedTemplateContext = webInterface.templateContextFactory.createTemplateContext()
.mergeContext(templateContext)
.apply {
- this["core"] = webInterface.core
+ this["core"] = core
this["currentSone"] = currentSone
- this["localSones"] = webInterface.core.localSones
+ this["localSones"] = core.localSones
this["request"] = freenetRequest
this["currentVersion"] = SonePlugin.getPluginVersion()
- this["hasLatestVersion"] = webInterface.core.updateChecker.hasLatestVersion()
- this["latestEdition"] = webInterface.core.updateChecker.latestEdition
- this["latestVersion"] = webInterface.core.updateChecker.latestVersion
- this["latestVersionTime"] = webInterface.core.updateChecker.latestVersionDate
+ this["hasLatestVersion"] = core.updateChecker.hasLatestVersion()
+ this["latestEdition"] = core.updateChecker.latestEdition
+ this["latestVersion"] = core.updateChecker.latestVersion
+ this["latestVersionTime"] = core.updateChecker.latestVersionDate
this["notification"] = this@render
}
it.also { render(mergedTemplateContext, it) }
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["post"]
- .let(webInterface.core::getPost)
+ .let(core::getPost)
.let { post ->
createSuccessJsonObject().
put("post", jsonObject(
private fun Post.render(currentSone: Sone, request: FreenetRequest) =
webInterface.templateContextFactory.createTemplateContext().apply {
- set("core", webInterface.core)
+ set("core", core)
set("request", request)
set("post", this@render)
set("currentSone", currentSone)
- set("localSones", webInterface.core.localSones)
+ set("localSones", core.localSones)
}.let { postTemplate.render(it) }
}
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["reply"]
- .let(webInterface.core::getPostReply)
+ .let(core::getPostReply)
?.let { it.toJson(currentSone, request) }
?.let { replyJson ->
createSuccessJsonObject().apply {
private fun PostReply.render(currentSone: Sone, request: FreenetRequest) =
webInterface.templateContextFactory.createTemplateContext().apply {
- set("core", webInterface.core)
+ set("core", core)
set("request", request)
set("reply", this@render)
set("currentSone", currentSone)
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))
override fun createJsonObject(request: FreenetRequest) =
createSuccessJsonObject().apply {
- put("postTimes", request.parameters["posts"]!!.idsToJson { webInterface.core.getPost(it)?.let { it.id to it.time } })
- put("replyTimes", request.parameters["replies"]!!.idsToJson { webInterface.core.getPostReply(it)?.let { it.id to it.time } })
+ put("postTimes", request.parameters["posts"]!!.idsToJson { core.getPost(it)?.let { it.id to it.time } })
+ put("replyTimes", request.parameters["replies"]!!.idsToJson { core.getPostReply(it)?.let { it.id to it.time } })
}
private fun String.idsToJson(transform: (String) -> Pair<String, Long>?) =
private val objectMapper = ObjectMapper()
private val sessionProvider: SessionProvider = webInterface
+ protected val core = webInterface.core
override fun getPath() = path
override fun isPrefixPage() = false
sessionProvider.getCurrentSone(toadletContext, createSession)
override fun handleRequest(request: FreenetRequest, response: Response): Response {
- if (webInterface.core.preferences.isRequireFullAccess && !request.toadletContext.isAllowedFullAccess) {
+ if (core.preferences.isRequireFullAccess && !request.toadletContext.isAllowedFullAccess) {
return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(createErrorJsonObject("auth-required").asJsonString())
}
if (needsFormPassword() && request.parameters["formPassword"] != webInterface.formPassword) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
when (request.parameters["type"]) {
"post" -> request.parameters["post"]
- .let(webInterface.core::getPost)
+ .let(core::getPost)
?.let { currentSone.addLikedPostId(it.id) }
- ?.also { webInterface.core.touchConfiguration() }
+ ?.also { core.touchConfiguration() }
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-post-id")
"reply" -> request.parameters["reply"]
- .let(webInterface.core::getPostReply)
+ .let(core::getPostReply)
?.let { currentSone.addLikedReplyId(it.id) }
- ?.also { webInterface.core.touchConfiguration() }
+ ?.also { core.touchConfiguration() }
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-reply-id")
else -> createErrorJsonObject("invalid-type")
override fun createJsonObject(request: FreenetRequest) =
request.parameters["sone"]
- .let(webInterface.core::getLocalSone)
- ?.let(webInterface.core::lockSone)
+ .let(core::getLocalSone)
+ ?.let(core::lockSone)
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-sone-id")
override fun requiresLogin() = false
override fun createJsonObject(request: FreenetRequest) = when (request.parameters["type"]) {
- "sone" -> processIds(request, webInterface.core::getSone, webInterface.core::markSoneKnown)
- "post" -> processIds(request, webInterface.core::getPost, webInterface.core::markPostKnown)
- "reply" -> processIds(request, webInterface.core::getPostReply, webInterface.core::markReplyKnown)
+ "sone" -> processIds(request, core::getSone, core::markSoneKnown)
+ "post" -> processIds(request, core::getPost, core::markPostKnown)
+ "reply" -> processIds(request, core::getPostReply, core::markReplyKnown)
else -> createErrorJsonObject("invalid-type")
}
else -> null
}?.let {
currentSone.profile = profile
- webInterface.core.touchConfiguration()
+ core.touchConfiguration()
createSuccessJsonObject()
} ?: createErrorJsonObject("invalid-direction")
} catch (e: IllegalArgumentException) {
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
- .let(webInterface.core::getSone)
- ?.let { webInterface.core.trustSone(currentSone, it) }
- ?.let { createSuccessJsonObject().put("trustValue", webInterface.core.preferences.positiveTrust) }
+ .let(core::getSone)
+ ?.let { core.trustSone(currentSone, it) }
+ ?.let { createSuccessJsonObject().put("trustValue", core.preferences.positiveTrust) }
?: createErrorJsonObject("invalid-sone-id")
}
override fun createJsonObject(request: FreenetRequest) =
request.parameters["post"]
- ?.let(webInterface.core::getPost)
- ?.also(webInterface.core::unbookmarkPost)
+ ?.let(core::getPost)
+ ?.also(core::unbookmarkPost)
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-post-id")
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
- ?.takeIf { webInterface.core.getSone(it).isPresent }
- ?.also { webInterface.core.unfollowSone(currentSone, it) }
+ ?.takeIf { core.getSone(it).isPresent }
+ ?.also { core.unfollowSone(currentSone, it) }
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-sone-id")
private fun FreenetRequest.processEntity(entity: String, likeRemover: (String) -> Unit) =
parameters[entity].emptyToNull
?.also(likeRemover)
- ?.also { webInterface.core.touchConfiguration() }
+ ?.also { core.touchConfiguration() }
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-$entity-id")
override fun createJsonObject(request: FreenetRequest) =
request.parameters["sone"]
- ?.let(webInterface.core::getLocalSone)
- ?.also(webInterface.core::unlockSone)
- ?.also { webInterface.core.touchConfiguration() }
+ ?.let(core::getLocalSone)
+ ?.also(core::unlockSone)
+ ?.also { core.touchConfiguration() }
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-sone-id")
override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
request.parameters["sone"]
- ?.let(webInterface.core::getSone)
- ?.also { webInterface.core.untrustSone(currentSone, it) }
+ ?.let(core::getSone)
+ ?.also { core.untrustSone(currentSone, it) }
?.let { createSuccessJsonObject() }
?: createErrorJsonObject("invalid-sone-id")