From: David ‘Bombe’ Roden Date: Tue, 5 Apr 2011 13:47:01 +0000 (+0200) Subject: Implement auto-following of new Sones. X-Git-Tag: 0.6.1^2~31 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=405b583a558a067d9bcb8217004e14ac93aa2af2;p=Sone.git Implement auto-following of new Sones. This fixes #88. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 731fcbd..ad1b1aa 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -905,6 +905,11 @@ public class Core implements IdentityListener, UpdateListener { } if (newSone) { coreListenerManager.fireNewSoneFound(sone); + for (Sone localSone : getLocalSones()) { + if (localSone.getOptions().getBooleanOption("AutoFollow").get()) { + localSone.addFriend(sone.getId()); + } + } } } remoteSones.put(identity.getId(), sone); @@ -1263,6 +1268,10 @@ public class Core implements IdentityListener, UpdateListener { friends.add(friendId); } + /* load options. */ + sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption(false)); + sone.getOptions().getBooleanOption("AutoFollow").set(configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").getValue(null)); + /* if we’re still here, Sone was loaded successfully. */ synchronized (sone) { sone.setTime(soneTime); @@ -1378,6 +1387,9 @@ public class Core implements IdentityListener, UpdateListener { } configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(null); + /* save options. */ + configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().getBooleanOption("AutoFollow").getReal()); + configuration.save(); logger.log(Level.INFO, "Sone %s saved.", sone); } catch (ConfigurationException ce1) { diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java index 84d7c79..77b4950 100644 --- a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java +++ b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.core.Core.Preferences; +import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; @@ -53,7 +54,13 @@ public class OptionsPage extends SoneTemplatePage { protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Preferences preferences = webInterface.getCore().getPreferences(); + Sone currentSone = webInterface.getCurrentSone(request.getToadletContext(), false); if (request.getMethod() == Method.POST) { + if (currentSone != null) { + boolean autoFollow = request.getHttpRequest().isPartSet("auto-follow"); + currentSone.getOptions().getBooleanOption("AutoFollow").set(autoFollow); + webInterface.getCore().saveSone(currentSone); + } Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16)); preferences.setInsertionDelay(insertionDelay); Integer positiveTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("positive-trust", 3)); @@ -74,6 +81,9 @@ public class OptionsPage extends SoneTemplatePage { webInterface.getCore().saveConfiguration(); throw new RedirectException(getPath()); } + if (currentSone != null) { + templateContext.set("auto-follow", currentSone.getOptions().getBooleanOption("AutoFollow").get()); + } templateContext.set("insertion-delay", preferences.getInsertionDelay()); templateContext.set("positive-trust", preferences.getPositiveTrust()); templateContext.set("negative-trust", preferences.getNegativeTrust()); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 5179709..e8d36a0 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -31,6 +31,9 @@ Page.About.License.Title=License Page.Options.Title=Options - Sone Page.Options.Page.Title=Options Page.Options.Page.Description=These options influence the runtime behaviour of the Sone plugin. +Page.Options.Section.SoneSpecificOptions.Title=Sone-specific Options +Page.Options.Section.SoneSpecificOptions.NotLoggedIn=These options are only available if you are {link}logged in{/link}. +Page.Options.Option.AutoFollow.Description=If a new Sone is discovered, follow it automatically. Page.Options.Section.RuntimeOptions.Title=Runtime Behaviour Page.Options.Option.InsertionDelay.Description=The number of seconds the Sone inserter waits after a modification of a Sone before it is being inserted. Page.Options.Section.TrustOptions.Title=Trust Settings diff --git a/src/main/resources/templates/options.html b/src/main/resources/templates/options.html index 5c47764..4086306 100644 --- a/src/main/resources/templates/options.html +++ b/src/main/resources/templates/options.html @@ -15,6 +15,17 @@
+

<%= Page.Options.Section.SoneSpecificOptions.Title|l10n|html>

+ + <%ifnull currentSone> +

<%= Page.Options.Section.SoneSpecificOptions.NotLoggedIn|l10n|html|replace needle="{link}" replacement=''|replace needle="{/link}" replacement=''>

+ <%/if> + +

+ disabled="disabled"<%/if><%if auto-follow> checked="checked"<%/if> /> + <%= Page.Options.Option.AutoFollow.Description|l10n|html> +

+

<%= Page.Options.Section.RuntimeOptions.Title|l10n|html>

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