From: David ‘Bombe’ Roden
Date: Fri, 24 Jul 2015 14:47:26 +0000 (+0200)
Subject: Add compatibility mode for old post IDs
X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9359e98d853739ec57c24ef0ff2d69c8ce29847d;p=Sone.git
Add compatibility mode for old post IDs
---
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
index 0000000..6983632
--- /dev/null
+++ b/src/main/java/net/pterodactylus/sone/core/CompatibilityMode.java
@@ -0,0 +1,17 @@
+package net.pterodactylus.sone.core;
+
+import net.pterodactylus.sone.data.Post;
+
+/**
+ * Sone compatibility modes.
+ *
+ * @author David âBombeâ Roden
+ */
+public enum CompatibilityMode {
+
+ /**
+ * This mode causes Sone to use a postâs {@link Post#getInternalId() internal ID} to locate posts when parsing links.
+ */
+ oldElementIds,
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java
index d442e69..90fc314 100644
--- a/src/main/java/net/pterodactylus/sone/core/Core.java
+++ b/src/main/java/net/pterodactylus/sone/core/Core.java
@@ -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 compatibilityModes = EnumSet.noneOf(CompatibilityMode.class);
+
/** The times Sones were followed. */
private final Map soneFollowingTimes = new HashMap();
@@ -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.
*
diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java
index c38f97b..1332638 100644
--- a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java
+++ b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java
@@ -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));
}
}
diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties
index 40a12b1..ccc8657 100644
--- a/src/main/resources/i18n/sone.en.properties
+++ b/src/main/resources/i18n/sone.en.properties
@@ -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