From: David ‘Bombe’ Roden Date: Fri, 24 Jul 2015 19:56:52 +0000 (+0200) Subject: Use unique IDs for replies, too X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2ef163831826acdb2113f04278d90fa0a60d3f8e;p=Sone.git Use unique IDs for replies, too --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index c1d51a3..68cf4b2 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1512,7 +1512,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, int replyCounter = 0; for (PostReply reply : sone.getReplies()) { String replyPrefix = sonePrefix + "/Replies/" + replyCounter++; - configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getId()); + configuration.getStringValue(replyPrefix + "/ID").setValue(reply.getInternalId()); configuration.getStringValue(replyPrefix + "/Post/ID").setValue(reply.getPostId()); configuration.getLongValue(replyPrefix + "/Time").setValue(reply.getTime()); configuration.getStringValue(replyPrefix + "/Text").setValue(reply.getText()); diff --git a/src/main/java/net/pterodactylus/sone/data/Reply.java b/src/main/java/net/pterodactylus/sone/data/Reply.java index e9b7a1d..69769eb 100644 --- a/src/main/java/net/pterodactylus/sone/data/Reply.java +++ b/src/main/java/net/pterodactylus/sone/data/Reply.java @@ -62,6 +62,7 @@ public interface Reply> extends Identified { * @return The ID of the reply */ public String getId(); + String getInternalId(); /** * Returns the Sone that posted this reply. diff --git a/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java index a67081f..b3681d7 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.data.impl; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.database.SoneProvider; @@ -30,6 +31,8 @@ import net.pterodactylus.sone.database.SoneProvider; */ public abstract class ReplyImpl> implements Reply { + private final IdBuilder idBuilder = new IdBuilder(); + /** The Sone provider. */ private final SoneProvider soneProvider; @@ -75,6 +78,11 @@ public abstract class ReplyImpl> implements Reply { */ @Override public String getId() { + return idBuilder.buildId(soneId, id); + } + + @Override + public String getInternalId() { return id; } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java index a6686ca..eb98a1d 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.database.memory; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Sone; @@ -31,6 +32,8 @@ import com.google.common.base.Optional; */ class MemoryPostReply implements PostReply { + private final IdBuilder idBuilder = new IdBuilder(); + /** The database. */ private final MemoryDatabase database; @@ -89,6 +92,11 @@ class MemoryPostReply implements PostReply { */ @Override public String getId() { + return idBuilder.buildId(soneId, id); + } + + @Override + public String getInternalId() { return id; } diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java index f7ca132..8e48dd3 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; @@ -54,7 +55,7 @@ public class DeleteReplyPage extends SoneTemplatePage { @Override protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); - String replyId = request.getHttpRequest().getPartAsStringFailsafe("reply", 36); + String replyId = request.getHttpRequest().getPartAsStringFailsafe("reply", IdBuilder.ID_STRING_LENGTH); Optional reply = webInterface.getCore().getPostReply(replyId); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); if (request.getMethod() == Method.POST) { diff --git a/src/main/resources/templates/insert/sone.xml b/src/main/resources/templates/insert/sone.xml index 2dd9499..9d29d6b 100644 --- a/src/main/resources/templates/insert/sone.xml +++ b/src/main/resources/templates/insert/sone.xml @@ -41,7 +41,7 @@ <%foreach currentSone.replies reply> - <% reply.id> + <% reply.internalId> <% reply.postId|xml> <% reply.text|xml>