Implement core listener interface.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index bd12d5b..f0a1fb6 100644 (file)
@@ -30,6 +30,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.core.CoreListener;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
@@ -85,11 +86,14 @@ import freenet.l10n.BaseL10n;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class WebInterface {
+public class WebInterface implements CoreListener {
 
        /** The logger. */
        private static final Logger logger = Logging.getLogger(WebInterface.class);
 
+       /** The notification manager. */
+       private final NotificationManager notificationManager = new NotificationManager();
+
        /** The Sone plugin. */
        private final SonePlugin sonePlugin;
 
@@ -147,6 +151,15 @@ public class WebInterface {
        }
 
        /**
+        * Returns the notification manager.
+        *
+        * @return The notification manager
+        */
+       public NotificationManager getNotifications() {
+               return notificationManager;
+       }
+
+       /**
         * Returns the l10n helper of the node.
         *
         * @return The node’s l10n helper
@@ -192,13 +205,13 @@ public class WebInterface {
                Template startupNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/startupNotification.html"));
 
                final TemplateNotification startupNotification = new TemplateNotification(startupNotificationTemplate);
-               getCore().getNotifications().addNotification(startupNotification);
+               notificationManager.addNotification(startupNotification);
 
                Ticker.getInstance().registerEvent(System.currentTimeMillis() + (120 * 1000), new Runnable() {
 
                        @Override
                        public void run() {
-                               getCore().getNotifications().removeNotification(startupNotification);
+                               startupNotification.dismiss();
                        }
                }, "Sone Startup Notification Remover");
        }
@@ -320,6 +333,35 @@ public class WebInterface {
                }
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void newSoneFound(Sone sone) {
+               newSoneNotification.addSone(sone);
+               notificationManager.addNotification(newSoneNotification);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void newPostFound(Post post) {
+               /* TODO */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void newReplyFound(Reply reply) {
+               /* TODO */
+       }
+
        /**
         * Template provider implementation that uses
         * {@link WebInterface#createReader(String)} to load templates for