Move createReply() method.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 0e7f163..90443ce 100644 (file)
@@ -541,11 +541,31 @@ public class Core implements IdentityListener {
         *         otherwise
         */
        public boolean isNewPost(String postId) {
+               return isNewPost(postId, true);
+       }
+
+       /**
+        * Returns whether the given post ID is new. If {@code markAsKnown} is
+        * {@code true} then after this method returns the post ID is marked a known
+        * post ID.
+        *
+        * @param postId
+        *            The post ID
+        * @param markAsKnown
+        *            {@code true} to mark the post ID as known, {@code false} to
+        *            not to mark it as known
+        * @return {@code true} if the post is considered to be new, {@code false}
+        *         otherwise
+        */
+       public boolean isNewPost(String postId, boolean markAsKnown) {
                synchronized (newPosts) {
-                       boolean isNew = !knownPosts.contains(postId) && newPosts.remove(postId);
-                       knownPosts.add(postId);
-                       if (isNew) {
-                               coreListenerManager.fireMarkPostKnown(getPost(postId));
+                       boolean isNew = !knownPosts.contains(postId) && newPosts.contains(postId);
+                       if (markAsKnown) {
+                               newPosts.remove(postId);
+                               knownPosts.add(postId);
+                               if (isNew) {
+                                       coreListenerManager.fireMarkPostKnown(getPost(postId));
+                               }
                        }
                        return isNew;
                }
@@ -599,11 +619,29 @@ public class Core implements IdentityListener {
         *         otherwise
         */
        public boolean isNewReply(String replyId) {
+               return isNewReply(replyId, true);
+       }
+
+       /**
+        * Returns whether the reply with the given ID is new.
+        *
+        * @param replyId
+        *            The ID of the reply to check
+        * @param markAsKnown
+        *            {@code true} to mark the reply as known, {@code false} to not
+        *            to mark it as known
+        * @return {@code true} if the reply is considered to be new, {@code false}
+        *         otherwise
+        */
+       public boolean isNewReply(String replyId, boolean markAsKnown) {
                synchronized (newReplies) {
-                       boolean isNew = !knownReplies.contains(replyId) && newReplies.remove(replyId);
-                       knownReplies.add(replyId);
-                       if (isNew) {
-                               coreListenerManager.fireMarkReplyKnown(getReply(replyId));
+                       boolean isNew = !knownReplies.contains(replyId) && newReplies.contains(replyId);
+                       if (markAsKnown) {
+                               newReplies.remove(replyId);
+                               knownReplies.add(replyId);
+                               if (isNew) {
+                                       coreListenerManager.fireMarkReplyKnown(getReply(replyId));
+                               }
                        }
                        return isNew;
                }
@@ -1188,6 +1226,22 @@ public class Core implements IdentityListener {
        }
 
        /**
+        * Marks the given post as known, if it is currently a new post (according
+        * to {@link #isNewPost(String)}).
+        *
+        * @param post
+        *            The post to mark as known
+        */
+       public void markPostKnown(Post post) {
+               synchronized (newPosts) {
+                       if (newPosts.remove(post.getId())) {
+                               knownPosts.add(post.getId());
+                               coreListenerManager.fireMarkPostKnown(post);
+                       }
+               }
+       }
+
+       /**
         * Creates a new reply.
         *
         * @param sone
@@ -1252,6 +1306,22 @@ public class Core implements IdentityListener {
        }
 
        /**
+        * Marks the given reply as known, if it is currently a new reply (according
+        * to {@link #isNewReply(String)}).
+        *
+        * @param reply
+        *            The reply to mark as known
+        */
+       public void markReplyKnown(Reply reply) {
+               synchronized (newReplies) {
+                       if (newReplies.remove(reply.getId())) {
+                               knownReplies.add(reply.getId());
+                               coreListenerManager.fireMarkReplyKnown(reply);
+                       }
+               }
+       }
+
+       /**
         * Starts the core.
         */
        public void start() {