X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FOptionsPage.kt;h=27d85c2b2d2d5966578c4d258820472ef99f3d86;hp=c8295ac6c5140284bd76917d69004f9e1746be3f;hb=fc8e9ea5c978d2f5a00894e093364ae62f18934b;hpb=effe93c96b6555d9e4f5263ce0933daab365706e diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt index c8295ac..27d85c2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt @@ -10,24 +10,25 @@ import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext +import javax.inject.Inject /** * This page lets the user edit the options of the Sone plugin. */ -class OptionsPage(template: Template, webInterface: WebInterface): - SoneTemplatePage("options.html", template, "Page.Options.Title", webInterface, false) { +class OptionsPage @Inject constructor(template: Template, webInterface: WebInterface): + SoneTemplatePage("options.html", webInterface, template, "Page.Options.Title") { - override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if (request.isPOST) { + override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { + if (freenetRequest.isPOST) { val fieldsWithErrors = mutableListOf() - getCurrentSone(request.toadletContext)?.options?.let { options -> - val autoFollow = "auto-follow" in request.parameters - val loadLinkedImages = request.parameters["load-linked-images"].emptyToNull - val showCustomAvatars = request.parameters["show-custom-avatars"].emptyToNull - val enableSoneInsertNotification = "enable-sone-insert-notifications" in request.parameters - val showNewSoneNotification = "show-notification-new-sones" in request.parameters - val showNewPostNotification = "show-notification-new-posts" in request.parameters - val showNewReplyNotification = "show-notification-new-replies" in request.parameters + getCurrentSone(freenetRequest.toadletContext)?.options?.let { options -> + val autoFollow = "auto-follow" in freenetRequest.parameters + val loadLinkedImages = freenetRequest.parameters["load-linked-images"].emptyToNull + val showCustomAvatars = freenetRequest.parameters["show-custom-avatars"].emptyToNull + val enableSoneInsertNotification = "enable-sone-insert-notifications" in freenetRequest.parameters + val showNewSoneNotification = "show-notification-new-sones" in freenetRequest.parameters + val showNewPostNotification = "show-notification-new-posts" in freenetRequest.parameters + val showNewReplyNotification = "show-notification-new-replies" in freenetRequest.parameters options.isAutoFollow = autoFollow options.isSoneInsertNotificationEnabled = enableSoneInsertNotification @@ -37,31 +38,31 @@ class OptionsPage(template: Template, webInterface: WebInterface): loadLinkedImages?.also { if (cantSetOption { options.loadLinkedImages = LoadExternalContent.valueOf(loadLinkedImages) }) fieldsWithErrors += "load-linked-images" } showCustomAvatars?.also { if (cantSetOption { options.showCustomAvatars = LoadExternalContent.valueOf(showCustomAvatars) }) fieldsWithErrors += "show-custom-avatars" } } - val fullAccessRequired = "require-full-access" in request.parameters - val fcpInterfaceActive = "fcp-interface-active" in request.parameters + val fullAccessRequired = "require-full-access" in freenetRequest.parameters + val fcpInterfaceActive = "fcp-interface-active" in freenetRequest.parameters - webInterface.core.preferences.isRequireFullAccess = fullAccessRequired - webInterface.core.preferences.isFcpInterfaceActive = fcpInterfaceActive + webInterface.core.preferences.newRequireFullAccess = fullAccessRequired + webInterface.core.preferences.newFcpInterfaceActive = fcpInterfaceActive - val postsPerPage = request.parameters["posts-per-page"]?.toIntOrNull() - val charactersPerPost = request.parameters["characters-per-post"]?.toIntOrNull() - val postCutOffLength = request.parameters["post-cut-off-length"]?.toIntOrNull() - val imagesPerPage = request.parameters["images-per-page"]?.toIntOrNull() - val insertionDelay = request.parameters["insertion-delay"]?.toIntOrNull() - val fcpFullAccessRequired = request.parameters["fcp-full-access-required"]?.toIntOrNull() - val negativeTrust = request.parameters["negative-trust"]?.toIntOrNull() - val positiveTrust = request.parameters["positive-trust"]?.toIntOrNull() - val trustComment = request.parameters["trust-comment"]?.emptyToNull + val postsPerPage = freenetRequest.parameters["posts-per-page"]?.toIntOrNull() + val charactersPerPost = freenetRequest.parameters["characters-per-post"]?.toIntOrNull() + val postCutOffLength = freenetRequest.parameters["post-cut-off-length"]?.toIntOrNull() + val imagesPerPage = freenetRequest.parameters["images-per-page"]?.toIntOrNull() + val insertionDelay = freenetRequest.parameters["insertion-delay"]?.toIntOrNull() + val fcpFullAccessRequired = freenetRequest.parameters["fcp-full-access-required"]?.toIntOrNull() + val negativeTrust = freenetRequest.parameters["negative-trust"]?.toIntOrNull() + val positiveTrust = freenetRequest.parameters["positive-trust"]?.toIntOrNull() + val trustComment = freenetRequest.parameters["trust-comment"]?.emptyToNull - if (cantSetOption { it.setPostsPerPage(postsPerPage) }) fieldsWithErrors += "posts-per-page" - if (cantSetOption { it.setCharactersPerPost(charactersPerPost) }) fieldsWithErrors += "characters-per-post" - if (cantSetOption { it.setPostCutOffLength(postCutOffLength) }) fieldsWithErrors += "post-cut-off-length" - if (cantSetOption { it.setImagesPerPage(imagesPerPage) }) fieldsWithErrors += "images-per-page" - if (cantSetOption { it.setInsertionDelay(insertionDelay) }) fieldsWithErrors += "insertion-delay" - fcpFullAccessRequired?.also { if (cantSetOption { it.fcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequired] }) fieldsWithErrors += "fcp-full-access-required" } - if (cantSetOption { it.setNegativeTrust(negativeTrust) }) fieldsWithErrors += "negative-trust" - if (cantSetOption { it.setPositiveTrust(positiveTrust) }) fieldsWithErrors += "positive-trust" - if (cantSetOption { it.trustComment = trustComment }) fieldsWithErrors += "trust-comment" + if (cantSetOption { it.newPostsPerPage = postsPerPage }) fieldsWithErrors += "posts-per-page" + if (cantSetOption { it.newCharactersPerPost = charactersPerPost }) fieldsWithErrors += "characters-per-post" + if (cantSetOption { it.newPostCutOffLength = postCutOffLength }) fieldsWithErrors += "post-cut-off-length" + if (cantSetOption { it.newImagesPerPage = imagesPerPage }) fieldsWithErrors += "images-per-page" + if (cantSetOption { it.newInsertionDelay = insertionDelay }) fieldsWithErrors += "insertion-delay" + fcpFullAccessRequired?.also { if (cantSetOption { it.newFcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequired] }) fieldsWithErrors += "fcp-full-access-required" } + if (cantSetOption { it.newNegativeTrust = negativeTrust }) fieldsWithErrors += "negative-trust" + if (cantSetOption { it.newPositiveTrust = positiveTrust }) fieldsWithErrors += "positive-trust" + if (cantSetOption { it.newTrustComment = trustComment }) fieldsWithErrors += "trust-comment" if (fieldsWithErrors.isEmpty()) { webInterface.core.touchConfiguration() @@ -69,7 +70,7 @@ class OptionsPage(template: Template, webInterface: WebInterface): } templateContext["fieldErrors"] = fieldsWithErrors } - getCurrentSone(request.toadletContext)?.options?.let { options -> + getCurrentSone(freenetRequest.toadletContext)?.options?.let { options -> templateContext["auto-follow"] = options.isAutoFollow templateContext["show-notification-new-sones"] = options.isShowNewSoneNotifications templateContext["show-notification-new-posts"] = options.isShowNewPostNotifications @@ -83,8 +84,8 @@ class OptionsPage(template: Template, webInterface: WebInterface): templateContext["characters-per-post"] = preferences.charactersPerPost templateContext["fcp-full-access-required"] = preferences.fcpFullAccessRequired.ordinal templateContext["images-per-page"] = preferences.imagesPerPage - templateContext["fcp-interface-active"] = preferences.isFcpInterfaceActive - templateContext["require-full-access"] = preferences.isRequireFullAccess + templateContext["fcp-interface-active"] = preferences.fcpInterfaceActive + templateContext["require-full-access"] = preferences.requireFullAccess templateContext["negative-trust"] = preferences.negativeTrust templateContext["positive-trust"] = preferences.positiveTrust templateContext["post-cut-off-length"] = preferences.postCutOffLength