Add events for marked known posts and replies.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index 1c429e7..0002e2c 100644 (file)
@@ -30,12 +30,14 @@ 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;
 import net.pterodactylus.sone.freenet.L10nFilter;
 import net.pterodactylus.sone.freenet.wot.Identity;
 import net.pterodactylus.sone.main.SonePlugin;
+import net.pterodactylus.sone.notify.NewSoneNotification;
 import net.pterodactylus.sone.template.CollectionAccessor;
 import net.pterodactylus.sone.template.CssClassNameFilter;
 import net.pterodactylus.sone.template.GetPagePlugin;
@@ -85,7 +87,7 @@ 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);
@@ -105,6 +107,9 @@ public class WebInterface {
        /** The template factory. */
        private DefaultTemplateFactory templateFactory;
 
+       /** The “new Sone” notification. */
+       private final NewSoneNotification newSoneNotification;
+
        /**
         * Creates a new web interface.
         *
@@ -134,6 +139,10 @@ public class WebInterface {
                templateFactory.addPlugin("paginate", new PaginationPlugin());
                templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory));
                templateFactory.addTemplateObject("formPassword", formPassword);
+
+               /* create notifications. */
+               Template newSoneNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newSoneNotification.html"));
+               newSoneNotification = new NewSoneNotification(newSoneNotificationTemplate);
        }
 
        //
@@ -332,6 +341,62 @@ 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 */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void markSoneKnown(Sone sone) {
+               newSoneNotification.removeSone(sone);
+               if (newSoneNotification.isEmpty()) {
+                       newSoneNotification.dismiss();
+               }
+       }
+
+       /**
+        * {@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