Save Sone after rescuing.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index d2c1420..33c4dbb 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);
                        }
@@ -712,6 +726,7 @@ public class Core implements IdentityListener {
                                                return;
                                        }
                                        logger.log(Level.INFO, "Trying to restore Sone from Freenet…");
+                                       coreListenerManager.fireRescuingSone(sone);
                                        lockSone(sone);
                                        long edition = sone.getLatestEdition();
                                        while (!stopped && (edition >= 0) && isSoneRescueMode()) {
@@ -720,6 +735,8 @@ public class Core implements IdentityListener {
                                                --edition;
                                        }
                                        logger.log(Level.INFO, "Finished restoring Sone from Freenet, starting Inserter…");
+                                       saveSone(sone);
+                                       coreListenerManager.fireRescuedSone(sone);
                                        soneInserter.start();
                                }
 
@@ -807,8 +824,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);
                                                }
@@ -824,6 +841,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);