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

index 81e5e09..e42a055 100644 (file)
@@ -42,6 +42,7 @@ import net.pterodactylus.sone.core.event.NewPostFoundEvent;
 import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
 import net.pterodactylus.sone.core.event.PostRemovedEvent;
+import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
@@ -1133,7 +1134,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                        for (PostReply reply : storedSone.getReplies()) {
                                                replies.remove(reply.getId());
                                                if (!sone.getReplies().contains(reply)) {
-                                                       coreListenerManager.fireReplyRemoved(reply);
+                                                       eventBus.post(new PostReplyRemovedEvent(reply));
                                                }
                                        }
                                }
@@ -2428,7 +2429,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        synchronized (knownReplies) {
                                for (PostReply reply : sone.getReplies()) {
                                        replies.remove(reply.getId());
-                                       coreListenerManager.fireReplyRemoved(reply);
+                                       eventBus.post(new PostReplyRemovedEvent(reply));
                                }
                        }
                }
index 937ffb6..0ae6fe1 100644 (file)
@@ -20,7 +20,6 @@ package net.pterodactylus.sone.core;
 import java.util.EventListener;
 
 import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.version.Version;
 
@@ -33,14 +32,6 @@ import net.pterodactylus.util.version.Version;
 public interface CoreListener extends EventListener {
 
        /**
-        * Notifies a listener that the given reply was removed.
-        *
-        * @param reply
-        *            The removed reply
-        */
-       public void replyRemoved(PostReply reply);
-
-       /**
         * Notifies a listener when a Sone was locked.
         *
         * @param sone
index a0c6d22..031fdb3 100644 (file)
@@ -18,7 +18,6 @@
 package net.pterodactylus.sone.core;
 
 import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.event.AbstractListenerManager;
 import net.pterodactylus.util.version.Version;
@@ -45,19 +44,6 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
-        * Notifies all listener that the given reply was removed.
-        *
-        * @see CoreListener#replyRemoved(PostReply)
-        * @param reply
-        *            The removed reply
-        */
-       void fireReplyRemoved(PostReply reply) {
-               for (CoreListener coreListener : getListeners()) {
-                       coreListener.replyRemoved(reply);
-               }
-       }
-
-       /**
         * Notifies all listeners that the given Sone was locked.
         *
         * @see CoreListener#soneLocked(Sone)
diff --git a/src/main/java/net/pterodactylus/sone/core/event/PostReplyRemovedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/PostReplyRemovedEvent.java
new file mode 100644 (file)
index 0000000..60f6957
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Sone - PostRemovedEvent.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 {@link PostReply} was removed.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class PostReplyRemovedEvent extends PostReplyEvent {
+
+       /**
+        * Creates a new “post reply removed” event.
+        *
+        * @param postReply
+        *            The post reply that was removed
+        */
+       public PostReplyRemovedEvent(PostReply postReply) {
+               super(postReply);
+       }
+
+}
index 53f7dd9..4534c35 100644 (file)
@@ -44,6 +44,7 @@ import net.pterodactylus.sone.core.event.NewPostFoundEvent;
 import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
 import net.pterodactylus.sone.core.event.PostRemovedEvent;
+import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
@@ -913,15 +914,15 @@ public class WebInterface implements CoreListener {
                mentionNotification.remove(postRemovedEvent.post());
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link PostReply} was removed.
+        *
+        * @param postReplyRemovedEvent
+        *            The event
         */
-       @Override
-       public void replyRemoved(PostReply reply) {
+       @Subscribe
+       public void replyRemoved(PostReplyRemovedEvent postReplyRemovedEvent) {
+               PostReply reply = postReplyRemovedEvent.postReply();
                newReplyNotification.remove(reply);
                localReplyNotification.remove(reply);
                if (!getMentionedSones(reply.getText()).isEmpty()) {
@@ -935,6 +936,10 @@ public class WebInterface implements CoreListener {
                }
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */