Simplify parsing of post:// links
[Sone.git] / src / main / java / net / pterodactylus / sone / text / SoneTextParser.java
index a1675d7..7194b89 100644 (file)
@@ -204,19 +204,13 @@ 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()));
                                                } else {
-                                                       parts.add(new PlainTextPart(line));
-                                                       line = "";
+                                                       parts.add(new PlainTextPart(link));
                                                }
+                                               line = line.substring(link.length());
                                                continue;
                                        }