Add events for marked known posts and replies.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Nov 2010 19:48:36 +0000 (20:48 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Nov 2010 19:48:36 +0000 (20:48 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/CoreListener.java
src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index 0fbbf3c..4c08651 100644 (file)
@@ -488,6 +488,9 @@ public class Core implements IdentityListener {
                synchronized (newPosts) {
                        boolean isNew = !knownPosts.contains(postId) && newPosts.remove(postId);
                        knownPosts.add(postId);
+                       if (isNew) {
+                               coreListenerManager.fireMarkPostKnown(getPost(postId));
+                       }
                        return isNew;
                }
        }
@@ -543,6 +546,9 @@ public class Core implements IdentityListener {
                synchronized (newReplies) {
                        boolean isNew = !knownReplies.contains(replyId) && newReplies.remove(replyId);
                        knownReplies.add(replyId);
+                       if (isNew) {
+                               coreListenerManager.fireMarkReplyKnown(getReply(replyId));
+                       }
                        return isNew;
                }
        }
index f8278ed..ca99e87 100644 (file)
@@ -63,4 +63,20 @@ public interface CoreListener extends EventListener {
         */
        public void markSoneKnown(Sone sone);
 
+       /**
+        * Notifies a listener that the given post is now marked as known.
+        *
+        * @param post
+        *            The known post
+        */
+       public void markPostKnown(Post post);
+
+       /**
+        * Notifies a listener that the given reply is now marked as known.
+        *
+        * @param reply
+        *            The known reply
+        */
+       public void markReplyKnown(Reply reply);
+
 }
index f226723..74838a1 100644 (file)
@@ -95,4 +95,28 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
                }
        }
 
+       /**
+        * Notifies all listeners that the given post is now marked as known.
+        *
+        * @param post
+        *            The known post
+        */
+       void fireMarkPostKnown(Post post) {
+               for (CoreListener coreListener : getListeners()) {
+                       coreListener.markPostKnown(post);
+               }
+       }
+
+       /**
+        * Notifies all listeners that the given reply is now marked as known.
+        *
+        * @param reply
+        *            The known reply
+        */
+       void fireMarkReplyKnown(Reply reply) {
+               for (CoreListener coreListener : getListeners()) {
+                       coreListener.markReplyKnown(reply);
+               }
+       }
+
 }
index 5b9efb2..0002e2c 100644 (file)
@@ -382,6 +382,22 @@ public class WebInterface implements CoreListener {
        }
 
        /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void markPostKnown(Post post) {
+               /* TODO */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void markReplyKnown(Reply reply) {
+               /* TODO */
+       }
+
+       /**
         * Template provider implementation that uses
         * {@link WebInterface#createReader(String)} to load templates for
         * inclusion.