Store in post part whether the internal ID was used to create this part
[Sone.git] / src / main / java / net / pterodactylus / sone / text / SoneTextParser.java
index f628279..1573d1c 100644 (file)
@@ -168,7 +168,6 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                                        if (next > 0) {
                                                parts.add(new PlainTextPart(line.substring(0, next)));
                                                line = line.substring(next);
-                                               next = 0;
                                        }
                                        lineComplete = false;
 
@@ -205,23 +204,17 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                                                continue;
                                        }
                                        if (linkType == LinkType.POST) {
-                                               if (line.length() >= (7 + 36)) {
-                                                       String postId = line.substring(7, 43);
-                                                       Optional<Post> post = postProvider.getPost(postId);
-                                                       if (post.isPresent()) {
-                                                               parts.add(new PostPart(post.get()));
-                                                       } else {
-                                                               parts.add(new PlainTextPart(line.substring(0, 43)));
-                                                       }
-                                                       line = line.substring(43);
+                                               Optional<Post> post = postProvider.getPost(link.substring(7));
+                                               if (post.isPresent()) {
+                                                       parts.add(new PostPart(post.get(), link.substring(7).equals(post.get().getInternalId())));
                                                } else {
-                                                       parts.add(new PlainTextPart(line));
-                                                       line = "";
+                                                       parts.add(new PlainTextPart(link));
                                                }
+                                               line = line.substring(link.length());
                                                continue;
                                        }
 
-                                       if ((linkType == LinkType.KSK) || (linkType == LinkType.CHK) || (linkType == LinkType.SSK) || (linkType == LinkType.USK)) {
+                                       if (linkType.isFreenetLink()) {
                                                FreenetURI uri;
                                                if (name.indexOf('?') > -1) {
                                                        name = name.substring(0, name.indexOf('?'));
@@ -279,7 +272,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                }
                for (int partIndex = parts.size() - 1; partIndex >= 0; --partIndex) {
                        Part part = parts.getPart(partIndex);
-                       if (!(part instanceof PlainTextPart) || !"\n".equals(((PlainTextPart) part).getText())) {
+                       if (!(part instanceof PlainTextPart) || !"\n".equals(part.getText())) {
                                break;
                        }
                        parts.removePart(partIndex);