Convert “post reply marked as known” into EventBus-based event.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 16:25:15 +0000 (17:25 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 18:04:11 +0000 (19:04 +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/core/event/MarkPostReplyKnownEvent.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index 0d7acf5..cf395a5 100644 (file)
@@ -36,6 +36,7 @@ import net.pterodactylus.sone.core.Options.DefaultOption;
 import net.pterodactylus.sone.core.Options.Option;
 import net.pterodactylus.sone.core.Options.OptionWatcher;
 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
+import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent;
 import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
 import net.pterodactylus.sone.core.event.NewPostFoundEvent;
 import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
@@ -1736,7 +1737,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
        public void markReplyKnown(PostReply reply) {
                reply.setKnown(true);
                synchronized (knownReplies) {
-                       coreListenerManager.fireMarkReplyKnown(reply);
+                       eventBus.post(new MarkPostReplyKnownEvent(reply));
                        if (knownReplies.add(reply.getId())) {
                                touchConfiguration();
                        }
index 987a2c7..f2ec67a 100644 (file)
@@ -34,14 +34,6 @@ import net.pterodactylus.util.version.Version;
 public interface CoreListener extends EventListener {
 
        /**
-        * Notifies a listener that the given reply is now marked as known.
-        *
-        * @param reply
-        *            The known reply
-        */
-       public void markReplyKnown(PostReply reply);
-
-       /**
         * Notifies a listener that the given Sone was removed.
         *
         * @param sone
index ed3a6f0..a88bef5 100644 (file)
@@ -46,18 +46,6 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
-        * Notifies all listeners that the given reply is now marked as known.
-        *
-        * @param reply
-        *            The known reply
-        */
-       void fireMarkReplyKnown(PostReply reply) {
-               for (CoreListener coreListener : getListeners()) {
-                       coreListener.markReplyKnown(reply);
-               }
-       }
-
-       /**
         * Notifies all listener that the given Sone was removed.
         *
         * @see CoreListener#soneRemoved(Sone)
diff --git a/src/main/java/net/pterodactylus/sone/core/event/MarkPostReplyKnownEvent.java b/src/main/java/net/pterodactylus/sone/core/event/MarkPostReplyKnownEvent.java
new file mode 100644 (file)
index 0000000..85c048b
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Sone - MarkPostReplyKnownEvent.java - Copyright © 2013 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event;
+
+import net.pterodactylus.sone.data.PostReply;
+
+/**
+ * Event that signals that a {@line PostReply} has been marked as
+ * {@link PostReply#isKnown() known}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class MarkPostReplyKnownEvent extends PostReplyEvent {
+
+       /**
+        * Creates a new “post reply marked known” event.
+        *
+        * @param postReply
+        *            The post reply that was marked as known
+        */
+       public MarkPostReplyKnownEvent(PostReply postReply) {
+               super(postReply);
+       }
+
+}
index 74f9087..68ba585 100644 (file)
@@ -38,6 +38,7 @@ import java.util.logging.Logger;
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.core.CoreListener;
 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
+import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent;
 import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
 import net.pterodactylus.sone.core.event.NewPostFoundEvent;
 import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
@@ -858,20 +859,20 @@ public class WebInterface implements CoreListener {
                mentionNotification.remove(markPostKnownEvent.post());
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
         * {@inheritDoc}
         */
-       @Override
-       public void markReplyKnown(PostReply reply) {
-               newReplyNotification.remove(reply);
-               localReplyNotification.remove(reply);
-               mentionNotification.remove(reply.getPost());
+       @Subscribe
+       public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) {
+               newReplyNotification.remove(markPostReplyKnownEvent.postReply());
+               localReplyNotification.remove(markPostReplyKnownEvent.postReply());
+               mentionNotification.remove(markPostReplyKnownEvent.postReply().getPost());
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */