Always fix up posts and replies.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 806ac21..4561b6d 100644 (file)
@@ -495,9 +495,23 @@ public class Core implements IdentityListener {
         * @return The post, or {@code null} if there is no such post
         */
        public Post getPost(String postId) {
+               return getPost(postId, true);
+       }
+
+       /**
+        * Returns the post with the given ID, optionally creating a new post.
+        *
+        * @param postId
+        *            The ID of the post to get
+        * @param create
+        *            {@code true} it create a new post if no post with the given ID
+        *            exists, {@code false} to return {@code null}
+        * @return The post, or {@code null} if there is no such post
+        */
+       public Post getPost(String postId, boolean create) {
                synchronized (posts) {
                        Post post = posts.get(postId);
-                       if (post == null) {
+                       if ((post == null) && create) {
                                post = new Post(postId);
                                posts.put(postId, post);
                        }
@@ -809,8 +823,8 @@ public class Core implements IdentityListener {
                                }
                                synchronized (newPosts) {
                                        for (Post post : sone.getPosts()) {
+                                               post.setSone(getSone(post.getSone().getId()));
                                                if (!storedSone.getPosts().contains(post) && !knownPosts.contains(post.getId())) {
-                                                       post.setSone(getSone(post.getSone().getId()));
                                                        newPosts.add(post.getId());
                                                        coreListenerManager.fireNewPostFound(post);
                                                }
@@ -826,6 +840,7 @@ public class Core implements IdentityListener {
                                }
                                synchronized (newReplies) {
                                        for (Reply reply : sone.getReplies()) {
+                                               reply.setSone(getSone(reply.getSone().getId()));
                                                if (!storedSone.getReplies().contains(reply) && !knownReplies.contains(reply.getId())) {
                                                        newReplies.add(reply.getId());
                                                        coreListenerManager.fireNewReplyFound(reply);