Add compatibility mode for old post IDs
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 24 Jul 2015 14:47:26 +0000 (16:47 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 24 Jul 2015 18:48:00 +0000 (20:48 +0200)
src/main/java/net/pterodactylus/sone/core/CompatibilityMode.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/web/OptionsPage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/options.html

diff --git a/src/main/java/net/pterodactylus/sone/core/CompatibilityMode.java b/src/main/java/net/pterodactylus/sone/core/CompatibilityMode.java
new file mode 100644 (file)
index 0000000..6983632
--- /dev/null
@@ -0,0 +1,17 @@
+package net.pterodactylus.sone.core;
+
+import net.pterodactylus.sone.data.Post;
+
+/**
+ * Sone compatibility modes.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public enum CompatibilityMode {
+
+       /**
+        * This mode causes Sone to use a post’s {@link Post#getInternalId() internal ID} to locate posts when parsing links.
+        */
+       oldElementIds,
+
+}
index d442e69..90fc314 100644 (file)
@@ -27,6 +27,7 @@ import static java.util.logging.Logger.getLogger;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -154,6 +155,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
        /** The trust updater. */
        private final WebOfTrustUpdater webOfTrustUpdater;
 
+       private final Set<CompatibilityMode> compatibilityModes = EnumSet.noneOf(CompatibilityMode.class);
+
        /** The times Sones were followed. */
        private final Map<String, Long> soneFollowingTimes = new HashMap<String, Long>();
 
@@ -273,6 +276,18 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                return updateChecker;
        }
 
+       public boolean isCompatibilityMode(CompatibilityMode compatibilityMode) {
+               return compatibilityModes.contains(compatibilityMode);
+       }
+
+       public void setCompatibilityMode(CompatibilityMode compatibilityMode) {
+               compatibilityModes.add(compatibilityMode);
+       }
+
+       public void clearCompatibilityMod(CompatibilityMode compatibilityMode) {
+               compatibilityModes.remove(compatibilityMode);
+       }
+
        /**
         * Returns the Sone rescuer for the given local Sone.
         *
index c38f97b..1332638 100644 (file)
@@ -22,6 +22,7 @@ import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
 import java.util.ArrayList;
 import java.util.List;
 
+import net.pterodactylus.sone.core.CompatibilityMode;
 import net.pterodactylus.sone.core.Preferences;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
@@ -133,6 +134,14 @@ public class OptionsPage extends SoneTemplatePage {
                        Integer fcpFullAccessRequiredInteger = parseInt(request.getHttpRequest().getPartAsStringFailsafe("fcp-full-access-required", 1), preferences.getFcpFullAccessRequired().ordinal());
                        FullAccessRequired fcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequiredInteger];
                        preferences.setFcpFullAccessRequired(fcpFullAccessRequired);
+
+                       boolean compatOldElementIds = request.getHttpRequest().isPartSet("compat-old-element-ids");
+                       if (compatOldElementIds) {
+                               webInterface.getCore().setCompatibilityMode(CompatibilityMode.oldElementIds);
+                       } else {
+                               webInterface.getCore().clearCompatibilityMod(CompatibilityMode.oldElementIds);
+                       }
+
                        webInterface.getCore().touchConfiguration();
                        if (fieldErrors.isEmpty()) {
                                throw new RedirectException(getPath());
@@ -158,6 +167,7 @@ public class OptionsPage extends SoneTemplatePage {
                templateContext.set("trust-comment", preferences.getTrustComment());
                templateContext.set("fcp-interface-active", preferences.isFcpInterfaceActive());
                templateContext.set("fcp-full-access-required", preferences.getFcpFullAccessRequired().ordinal());
+               templateContext.set("compat-old-element-ids", webInterface.getCore().isCompatibilityMode(CompatibilityMode.oldElementIds));
        }
 
 }
index 40a12b1..ccc8657 100644 (file)
@@ -69,6 +69,9 @@ Page.Options.Option.FcpFullAccessRequired.Description=Require FCP connection fro
 Page.Options.Option.FcpFullAccessRequired.Value.No=No
 Page.Options.Option.FcpFullAccessRequired.Value.Writing=For Write Access
 Page.Options.Option.FcpFullAccessRequired.Value.Always=Always
+Page.Options.Section.CompatibilityOptions.Title=Compatibility Options
+Page.Options.Section.CompatibilityOptions.Description=These options control how much deprecated functionality Sone will support.
+Page.Options.Option.CompatibilityOptions.OldElementIds.Description=Support old post IDs in links. Activating this will try to locate a post linked to by an old ID even though it can not be guaranteed that it is the post that was originally linked to.
 Page.Options.Section.Cleaning.Title=Clean Up
 Page.Options.Option.ClearOnNextRestart.Description=Resets the configuration of the Sone plugin at the next restart. Warning! {strong}This will destroy all of your Sones{/strong} so make sure you have backed up everyhing you still need! Also, you need to set the next option to true to actually do it.
 Page.Options.Option.ReallyClearOnNextRestart.Description=This option needs to be set to “yes” if you really, {strong}really{/strong} want to clear the plugin configuration on the next restart.
@@ -463,3 +466,4 @@ Notification.Mention.Text=You have been mentioned in the following posts:
 Notification.SoneIsInserting.Text=Your Sone sone://{0} is now being inserted.
 Notification.SoneIsInserted.Text=Your Sone sone://{0} has been inserted in {1,number} {1,choice,0#seconds|1#second|1<seconds}.
 Notification.SoneInsertAborted.Text=Your Sone sone://{0} could not be inserted.
+# 72-74
index 4ec88cb..0879ed1 100644 (file)
                        </select>
                </p>
 
+        <h2><%= Page.Options.Section.CompatibilityOptions.Title|l10n|html></h2>
+
+        <p><%= Page.Options.Section.CompatibilityOptions.Description|l10n|html></p>
+
+        <p>
+            <input type="checkbox" name="compat-old-element-ids"<%if compat-old-element-ids> checked="checked"<%/if> />
+            <%= Page.Options.Option.CompatibilityOptions.OldElementIds.Description|l10n|html>
+        </p>
+
                <p><button type="submit"><%= Page.Options.Button.Save|l10n|html></button></p>
 
        </form>