From: David ‘Bombe’ Roden Date: Fri, 24 Jul 2015 13:39:22 +0000 (+0200) Subject: Use a unique ID for posts X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d72167e26461a77ad3b916cabf44df416ebb2a72;p=Sone.git Use a unique ID for posts --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index d0b31d0..d442e69 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1476,7 +1476,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, int postCounter = 0; for (Post post : sone.getPosts()) { String postPrefix = sonePrefix + "/Posts/" + postCounter++; - configuration.getStringValue(postPrefix + "/ID").setValue(post.getId()); + configuration.getStringValue(postPrefix + "/ID").setValue(post.getInternalId()); configuration.getStringValue(postPrefix + "/Recipient").setValue(post.getRecipientId().orNull()); configuration.getLongValue(postPrefix + "/Time").setValue(post.getTime()); configuration.getStringValue(postPrefix + "/Text").setValue(post.getText()); diff --git a/src/main/java/net/pterodactylus/sone/data/Post.java b/src/main/java/net/pterodactylus/sone/data/Post.java index 95abae6..d27d243 100644 --- a/src/main/java/net/pterodactylus/sone/data/Post.java +++ b/src/main/java/net/pterodactylus/sone/data/Post.java @@ -62,6 +62,7 @@ public interface Post extends Identified { * @return The ID of the post */ public String getId(); + String getInternalId(); /** * Returns whether this post has already been loaded. @@ -144,6 +145,11 @@ public interface Post extends Identified { } @Override + public String getInternalId() { + return id; + } + + @Override public boolean isLoaded() { return false; } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java index 9dcd7d0..4442b3b 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.data.impl; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.database.SoneProvider; @@ -31,6 +32,8 @@ import com.google.common.base.Optional; */ public class PostImpl implements Post { + private final IdBuilder idBuilder = new IdBuilder(); + /** The Sone provider. */ private final SoneProvider soneProvider; @@ -86,6 +89,11 @@ public class PostImpl implements Post { */ @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/MemoryPost.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPost.java index 180cf6c..34e90f8 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPost.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPost.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.database.memory; import java.util.UUID; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.database.SoneProvider; @@ -33,6 +34,8 @@ import com.google.common.base.Optional; */ class MemoryPost implements Post { + private final IdBuilder idBuilder = new IdBuilder(); + /** The post database. */ private final MemoryDatabase postDatabase; @@ -91,6 +94,11 @@ class MemoryPost implements Post { */ @Override public String getId() { + return idBuilder.buildId(soneId, id.toString()); + } + + @Override + public String getInternalId() { return id.toString(); } diff --git a/src/main/java/net/pterodactylus/sone/web/BookmarkPage.java b/src/main/java/net/pterodactylus/sone/web/BookmarkPage.java index c0a8907..b053b5e 100644 --- a/src/main/java/net/pterodactylus/sone/web/BookmarkPage.java +++ b/src/main/java/net/pterodactylus/sone/web/BookmarkPage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; @@ -53,7 +54,7 @@ public class BookmarkPage extends SoneTemplatePage { protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { - String id = request.getHttpRequest().getPartAsStringFailsafe("post", 36); + String id = request.getHttpRequest().getPartAsStringFailsafe("post", IdBuilder.ID_STRING_LENGTH); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); Optional post = webInterface.getCore().getPost(id); if (post.isPresent()) { diff --git a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java index 55903d8..2e59de7 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web; import com.google.common.base.Optional; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.text.TextFilter; @@ -56,7 +57,7 @@ public class CreateReplyPage extends SoneTemplatePage { @Override protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); - String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); + String postId = request.getHttpRequest().getPartAsStringFailsafe("post", IdBuilder.ID_STRING_LENGTH); String text = request.getHttpRequest().getPartAsStringFailsafe("text", 65536).trim(); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); if (request.getMethod() == Method.POST) { diff --git a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java index 5a309fa..c8e0af0 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web; import com.google.common.base.Optional; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; @@ -64,7 +65,7 @@ public class DeletePostPage extends SoneTemplatePage { templateContext.set("post", post.get()); templateContext.set("returnPage", returnPage); } else if (request.getMethod() == Method.POST) { - String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); + String postId = request.getHttpRequest().getPartAsStringFailsafe("post", IdBuilder.ID_STRING_LENGTH); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); Optional post = webInterface.getCore().getPost(postId); if (!post.isPresent() || !post.get().getSone().isLocal()) { diff --git a/src/main/java/net/pterodactylus/sone/web/LikePage.java b/src/main/java/net/pterodactylus/sone/web/LikePage.java index 7f08e65..30bf4f0 100644 --- a/src/main/java/net/pterodactylus/sone/web/LikePage.java +++ b/src/main/java/net/pterodactylus/sone/web/LikePage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.FreenetRequest; @@ -55,7 +56,7 @@ public class LikePage extends SoneTemplatePage { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16); - String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36); + String id = request.getHttpRequest().getPartAsStringFailsafe(type, IdBuilder.ID_STRING_LENGTH); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); Sone currentSone = getCurrentSone(request.getToadletContext()); if ("post".equals(type)) { diff --git a/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java b/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java index 72ff2fc..3be06ae 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web; import java.util.Set; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; @@ -55,7 +56,7 @@ public class UnbookmarkPage extends SoneTemplatePage { protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { - String id = request.getHttpRequest().getPartAsStringFailsafe("post", 36); + String id = request.getHttpRequest().getPartAsStringFailsafe("post", IdBuilder.ID_STRING_LENGTH); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); Optional post = webInterface.getCore().getPost(id); if (post.isPresent()) { diff --git a/src/main/java/net/pterodactylus/sone/web/UnlikePage.java b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java index 9254a42..16291bf 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnlikePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import net.pterodactylus.sone.data.IdBuilder; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.FreenetRequest; @@ -55,7 +56,7 @@ public class UnlikePage extends SoneTemplatePage { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16); - String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36); + String id = request.getHttpRequest().getPartAsStringFailsafe(type, IdBuilder.ID_STRING_LENGTH); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); Sone currentSone = getCurrentSone(request.getToadletContext()); if ("post".equals(type)) { diff --git a/src/main/resources/templates/insert/sone.xml b/src/main/resources/templates/insert/sone.xml index 10e57eb..2dd9499 100644 --- a/src/main/resources/templates/insert/sone.xml +++ b/src/main/resources/templates/insert/sone.xml @@ -30,7 +30,7 @@ <%foreach currentSone.posts post> - <% post.id|xml> + <% post.internalId|xml> <%if post.recipientId.present><% post.recipientId.get|xml><%/if> <% post.text|xml>