From: David ‘Bombe’ Roden Date: Mon, 20 Jul 2026 16:52:17 +0000 (+0200) Subject: ✨ Add new option for max age of posts to load X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2fb701c9ee3d604810afc6be083a5c18deafba5a;p=Sone.git ✨ Add new option for max age of posts to load --- 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 6362cdb..3e2c342 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt @@ -52,6 +52,7 @@ class OptionsPage @Inject constructor(webInterface: WebInterface, loaders: Loade val imagesPerPage = soneRequest.parameters["images-per-page"]?.toIntOrNull() val insertionDelay = soneRequest.parameters["insertion-delay"]?.toIntOrNull() val fcpFullAccessRequired = soneRequest.parameters["fcp-full-access-required"]?.toIntOrNull() + val maxAgeOfPostsToLoad = soneRequest.parameters["max-age-of-posts-to-load"]?.toIntOrNull() if (cantSetOption { soneRequest.core.preferences.newPostsPerPage = postsPerPage }) fieldsWithErrors += "posts-per-page" if (cantSetOption { soneRequest.core.preferences.newCharactersPerPost = charactersPerPost }) fieldsWithErrors += "characters-per-post" @@ -59,6 +60,7 @@ class OptionsPage @Inject constructor(webInterface: WebInterface, loaders: Loade if (cantSetOption { soneRequest.core.preferences.newImagesPerPage = imagesPerPage }) fieldsWithErrors += "images-per-page" if (cantSetOption { soneRequest.core.preferences.newInsertionDelay = insertionDelay }) fieldsWithErrors += "insertion-delay" fcpFullAccessRequired?.also { if (cantSetOption { soneRequest.core.preferences.newFcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequired] }) fieldsWithErrors += "fcp-full-access-required" } + if (cantSetOption { soneRequest.core.preferences.newMaxAgeOfPostsToLoad = maxAgeOfPostsToLoad }) fieldsWithErrors += "max-age-of-posts-to-load" if (fieldsWithErrors.isEmpty()) { soneRequest.core.touchConfiguration() @@ -85,6 +87,7 @@ class OptionsPage @Inject constructor(webInterface: WebInterface, loaders: Loade templateContext["post-cut-off-length"] = preferences.postCutOffLength templateContext["posts-per-page"] = preferences.postsPerPage templateContext["strict-filtering"] = preferences.strictFiltering + templateContext["max-age-of-posts-to-load"] = preferences.maxAgeOfPostsToLoad } } diff --git a/src/main/resources/i18n/sone.de.properties b/src/main/resources/i18n/sone.de.properties index 5b2a2a0..6b212f4 100644 --- a/src/main/resources/i18n/sone.de.properties +++ b/src/main/resources/i18n/sone.de.properties @@ -66,6 +66,7 @@ Page.Options.Option.PostsPerPage.Description=Anzahl der Nachrichten pro Seite. Page.Options.Option.ImagesPerPage.Description=Anzahl der Bilder pro Seite. Page.Options.Option.CharactersPerPost.Description=Die Anzahl der Zeichen, die eine Nachricht enthalten muss, damit sie gekürzt angezeigt wird (-1 für „nie kürzen“). Die Anzahl der tatsächlich angezeigten Zeichen wird in der nächsten Option konfiguriert. Page.Options.Option.PostCutOffLength.Description=Die Anzahl der Zeichen, die von einer gekürzten Nachricht sichtbar sind (siehe Option hierüber). Wird ignoriert, wenn die Option hierüber deaktiviert ist, bzw. auf -1 steht. +Page.Options.Option.MaxAgeOfPostsToLoad.Description=Die Anzahl der Tage, die eine Nachricht oder eine Antwort maximal alt sein darf. Wenn dieser Wert erhöht wird, erhöht sich auch der Speicherbedarf von Sone. Der geänderte Wert wird nur angewendet, wenn eine Sone neu geladen wird, oder nach einem Neustart von Sone. Page.Options.Option.RequireFullAccess.Description=Zugriff auf Sone für alle Rechner, die keinen vollen Zugriff haben, unterbinden. Page.Options.Section.FcpOptions.Title=FCP-Schnittstellenoptionen Page.Options.Option.FcpInterfaceActive.Description=Die FCP-Schnittstelle aktivieren, um anderen Plugins und Programmen den Zugriff auf Ihr Sone-Plugin zu ermöglichen. @@ -427,6 +428,7 @@ WebInterface.DefaultText.Option.PostsPerPage=Anzahl der Nachrichten pro Seite WebInterface.DefaultText.Option.ImagesPerPage=Anzahl der Bilder pro Seite WebInterface.DefaultText.Option.CharactersPerPost=Anzahl der Zeichen, die eine Nachricht haben muss, damit er gekürzt wird WebInterface.DefaultText.Option.PostCutOffLength=Anzahl der Zeichen, die von einer gekürzten Nachricht angezeigt werden +WebInterface.DefaultText.Option.MaxAgeOfPostsToLoad=Anzahl der Tage, die Nachrichten oder Antworten maximal alt sein dürfen WebInterface.Button.Comment=Antworten WebInterface.Confirmation.DeletePostButton=Ja, löschen! WebInterface.Confirmation.DeleteReplyButton=Ja, löschen! diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 75036c4..f06a204 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -66,6 +66,7 @@ Page.Options.Option.PostsPerPage.Description=The number of posts to display on a Page.Options.Option.ImagesPerPage.Description=The number of images to display on a page before pagination controls are being shown. Page.Options.Option.CharactersPerPost.Description=The number of characters to display from a post before cutting it off and showing a link to expand it (-1 to disable). The actual length of the snippet is determined by the option below. Page.Options.Option.PostCutOffLength.Description=The number of characters that are displayed if a post is deemed too long (see option above). Ignored if “number of characters to display” is disabled (set to -1). +Page.Options.Option.MaxAgeOfPostsToLoad.Description=The number of days a post or reply may be old at most. Increasing this will make Sone use more memory. Changes will be applied when a Sone is being loaded, or when Sone is restarted. Page.Options.Option.RequireFullAccess.Description=Whether to deny access to Sone to any host that has not been granted full access. Page.Options.Section.FcpOptions.Title=FCP Interface Settings Page.Options.Option.FcpInterfaceActive.Description=Activate the FCP interface to allow other plugins and remote clients to access your Sone plugin. @@ -427,6 +428,7 @@ WebInterface.DefaultText.Option.PostsPerPage=Number of posts to show on a page WebInterface.DefaultText.Option.ImagesPerPage=Number of images to show on a page WebInterface.DefaultText.Option.CharactersPerPost=Number of characters a post must have to be shortened WebInterface.DefaultText.Option.PostCutOffLength=Number of characters for the snippet of the shortened post +WebInterface.DefaultText.Option.MaxAgeOfPostsToLoad=Number of days a post or reply may be old at most WebInterface.Button.Comment=Comment WebInterface.Confirmation.DeletePostButton=Yes, delete! WebInterface.Confirmation.DeleteReplyButton=Yes, delete! diff --git a/src/main/resources/templates/options.html b/src/main/resources/templates/options.html index 9ef5ceb..9cd2581 100644 --- a/src/main/resources/templates/options.html +++ b/src/main/resources/templates/options.html @@ -17,6 +17,9 @@ getTranslation("WebInterface.DefaultText.Option.PostCutOffLength", function(postCutOffLengthText) { registerInputTextareaSwap("#sone #options input[name=post-cut-off-length]", postCutOffLengthText, "post-cut-off-length", true, true); }); + getTranslation("WebInterface.DefaultText.Option.MaxAgeOfPostsToLoad", function(maxAgeOfPostsToLoadText) { + registerInputTextareaSwap("#sone #options input[name=max-age-of-posts-to-load]", maxAgeOfPostsToLoadText, "max-age-of-posts-to-load", true, true); + }); }); @@ -146,6 +149,12 @@ <%/if>

+

<%= Page.Options.Option.MaxAgeOfPostsToLoad.Description|l10n|html>

+ <%if =max-age-of-posts-to-load|in collection=fieldErrors> +

<%= Page.Options.Warnings.ValueNotChanged|l10n|html>

+ <%/if> +

+

checked="checked"<%/if> /> <%= Page.Options.Option.RequireFullAccess.Description|l10n|html>

diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt index d679e85..74ac256 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt @@ -28,6 +28,7 @@ class OptionsPageTest : WebPageTest(::OptionsPage) { core.preferences.newPostCutOffLength = 51 core.preferences.newPostsPerPage = 10 core.preferences.newStrictFiltering = true + core.preferences.newMaxAgeOfPostsToLoad = 123 } @Before @@ -78,6 +79,7 @@ class OptionsPageTest : WebPageTest(::OptionsPage) { assertThat(templateContext["post-cut-off-length"], equalTo(51)) assertThat(templateContext["posts-per-page"], equalTo(10)) assertThat(templateContext["strict-filtering"], equalTo(true)) + assertThat(templateContext["max-age-of-posts-to-load"], equalTo(123)) } } @@ -320,6 +322,26 @@ class OptionsPageTest : WebPageTest(::OptionsPage) { } @Test + fun `max age of posts to load can be set`() { + verifyThatPreferencesCanBeSet("max-age-of-posts-to-load", "23", 23) { core.preferences.maxAgeOfPostsToLoad } + } + + @Test + fun `max age of posts to load cannot be set to a negative value`() { + verifyThatWrongValueForPreferenceIsDetected("max-age-of-posts-to-load", "-23") + } + + @Test + fun `max age of posts to load is set to default on invalid value`() { + verifyThatPreferencesCanBeSet("max-age-of-posts-to-load", "invalid", 365) { core.preferences.maxAgeOfPostsToLoad } + } + + @Test + fun `max age of posts to load is set to default on empty value`() { + verifyThatPreferencesCanBeSet("max-age-of-posts-to-load", "", 365) { core.preferences.maxAgeOfPostsToLoad } + } + + @Test fun `page can be created by dependency injection`() { assertThat(baseInjector.getInstance(), notNullValue()) }