Convert “Sone insert was aborted” into EventBus-based event.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index 74f9087..7c16c09 100644 (file)
@@ -38,10 +38,19 @@ 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;
 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.SoneInsertAbortedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertingEvent;
+import net.pterodactylus.sone.core.event.SoneLockedEvent;
+import net.pterodactylus.sone.core.event.SoneRemovedEvent;
+import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Post;
@@ -784,7 +793,10 @@ public class WebInterface implements CoreListener {
        //
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a new {@link Sone} was found.
+        *
+        * @param newSoneFoundEvent
+        *            The event
         */
        @Subscribe
        public void newSoneFound(NewSoneFoundEvent newSoneFoundEvent) {
@@ -795,7 +807,10 @@ public class WebInterface implements CoreListener {
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a new {@link Post} was found.
+        *
+        * @param newPostFoundEvent
+        *            The event
         */
        @Subscribe
        public void newPostFound(NewPostFoundEvent newPostFoundEvent) {
@@ -818,7 +833,10 @@ public class WebInterface implements CoreListener {
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a new {@link PostReply} was found.
+        *
+        * @param newPostReplyFoundEvent
+        *            The event
         */
        @Subscribe
        public void newReplyFound(NewPostReplyFoundEvent newPostReplyFoundEvent) {
@@ -841,7 +859,10 @@ public class WebInterface implements CoreListener {
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Sone} was marked as known.
+        *
+        * @param markSoneKnownEvent
+        *            The event
         */
        @Subscribe
        public void markSoneKnown(MarkSoneKnownEvent markSoneKnownEvent) {
@@ -849,7 +870,10 @@ public class WebInterface implements CoreListener {
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Post} was marked as known.
+        *
+        * @param markPostKnownEvent
+        *            The event
         */
        @Subscribe
        public void markPostKnown(MarkPostKnownEvent markPostKnownEvent) {
@@ -858,43 +882,52 @@ public class WebInterface implements CoreListener {
                mentionNotification.remove(markPostKnownEvent.post());
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link PostReply} was marked as known.
+        *
+        * @param markPostReplyKnownEvent
+        *            The event
         */
-       @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());
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Sone} was removed.
+        *
+        * @param soneRemovedEvent
+        *            The event
         */
-       @Override
-       public void soneRemoved(Sone sone) {
-               newSoneNotification.remove(sone);
+       @Subscribe
+       public void soneRemoved(SoneRemovedEvent soneRemovedEvent) {
+               newSoneNotification.remove(soneRemovedEvent.sone());
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Post} was removed.
+        *
+        * @param postRemovedEvent
+        *            The event
         */
-       @Override
-       public void postRemoved(Post post) {
-               newPostNotification.remove(post);
-               localPostNotification.remove(post);
-               mentionNotification.remove(post);
+       @Subscribe
+       public void postRemoved(PostRemovedEvent postRemovedEvent) {
+               newPostNotification.remove(postRemovedEvent.post());
+               localPostNotification.remove(postRemovedEvent.post());
+               mentionNotification.remove(postRemovedEvent.post());
        }
 
        /**
-        * {@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()) {
@@ -909,10 +942,14 @@ public class WebInterface implements CoreListener {
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a Sone was locked.
+        *
+        * @param soneLockedEvent
+        *            The event
         */
-       @Override
-       public void soneLocked(final Sone sone) {
+       @Subscribe
+       public void soneLocked(SoneLockedEvent soneLockedEvent) {
+               final Sone sone = soneLockedEvent.sone();
                Object tickerObject = Ticker.getInstance().registerEvent(System.currentTimeMillis() + (5 * 60) * 1000, new Runnable() {
 
                        @Override
@@ -927,52 +964,68 @@ public class WebInterface implements CoreListener {
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a Sone was unlocked.
+        *
+        * @param soneUnlockedEvent
+        *            The event
         */
-       @Override
-       public void soneUnlocked(Sone sone) {
-               lockedSonesNotification.remove(sone);
-               Ticker.getInstance().deregisterEvent(lockedSonesTickerObjects.remove(sone));
+       @Subscribe
+       public void soneUnlocked(SoneUnlockedEvent soneUnlockedEvent) {
+               lockedSonesNotification.remove(soneUnlockedEvent.sone());
+               Ticker.getInstance().deregisterEvent(lockedSonesTickerObjects.remove(soneUnlockedEvent.sone()));
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Sone} is being inserted.
+        *
+        * @param soneInsertingEvent
+        *            The event
         */
-       @Override
-       public void soneInserting(Sone sone) {
-               TemplateNotification soneInsertNotification = getSoneInsertNotification(sone);
+       @Subscribe
+       public void soneInserting(SoneInsertingEvent soneInsertingEvent) {
+               TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertingEvent.sone());
                soneInsertNotification.set("soneStatus", "inserting");
-               if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+               if (soneInsertingEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
                        notificationManager.addNotification(soneInsertNotification);
                }
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Sone} was inserted.
+        *
+        * @param soneInsertedEvent
+        *            The event
         */
-       @Override
-       public void soneInserted(Sone sone, long insertDuration) {
-               TemplateNotification soneInsertNotification = getSoneInsertNotification(sone);
+       @Subscribe
+       public void soneInserted(SoneInsertedEvent soneInsertedEvent) {
+               TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertedEvent.sone());
                soneInsertNotification.set("soneStatus", "inserted");
-               soneInsertNotification.set("insertDuration", insertDuration / 1000);
-               if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+               soneInsertNotification.set("insertDuration", soneInsertedEvent.insertDuration() / 1000);
+               if (soneInsertedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
                        notificationManager.addNotification(soneInsertNotification);
                }
        }
 
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Sone} insert was aborted.
+        *
+        * @param soneInsertAbortedEvent
+        *            The event
         */
-       @Override
-       public void soneInsertAborted(Sone sone, Throwable cause) {
-               TemplateNotification soneInsertNotification = getSoneInsertNotification(sone);
+       @Subscribe
+       public void soneInsertAborted(SoneInsertAbortedEvent soneInsertAbortedEvent) {
+               TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertAbortedEvent.sone());
                soneInsertNotification.set("soneStatus", "insert-aborted");
-               soneInsertNotification.set("insert-error", cause);
-               if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+               soneInsertNotification.set("insert-error", soneInsertAbortedEvent.cause());
+               if (soneInsertAbortedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
                        notificationManager.addNotification(soneInsertNotification);
                }
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */