Use unique IDs for replies, too
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 24 Jul 2015 19:56:52 +0000 (21:56 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 24 Jul 2015 19:56:52 +0000 (21:56 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/data/Reply.java
src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java
src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java
src/main/resources/templates/insert/sone.xml

index c1d51a3..68cf4b2 100644 (file)
@@ -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());
index e9b7a1d..69769eb 100644 (file)
@@ -62,6 +62,7 @@ public interface Reply<T extends Reply<T>> extends Identified {
         * @return The ID of the reply
         */
        public String getId();
+       String getInternalId();
 
        /**
         * Returns the Sone that posted this reply.
index a67081f..b3681d7 100644 (file)
@@ -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<T extends Reply<T>> implements Reply<T> {
 
+       private final IdBuilder idBuilder = new IdBuilder();
+
        /** The Sone provider. */
        private final SoneProvider soneProvider;
 
@@ -75,6 +78,11 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
         */
        @Override
        public String getId() {
+               return idBuilder.buildId(soneId, id);
+       }
+
+       @Override
+       public String getInternalId() {
                return id;
        }
 
index a6686ca..eb98a1d 100644 (file)
@@ -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;
        }
 
index f7ca132..8e48dd3 100644 (file)
@@ -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<PostReply> reply = webInterface.getCore().getPostReply(replyId);
                String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                if (request.getMethod() == Method.POST) {
index 2dd9499..9d29d6b 100644 (file)
@@ -41,7 +41,7 @@
        <replies>
                <%foreach currentSone.replies reply>
                <reply>
-                       <id><% reply.id></id>
+                       <id><% reply.internalId></id>
                        <post-id><% reply.postId|xml></post-id>
                        <time><% reply.time></time>
                        <text><% reply.text|xml></text>