Add new reply notification.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index f0a1fb6..115e0c3 100644 (file)
@@ -37,6 +37,9 @@ 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.NewPostNotification;
+import net.pterodactylus.sone.notify.NewReplyNotification;
+import net.pterodactylus.sone.notify.NewSoneNotification;
 import net.pterodactylus.sone.template.CollectionAccessor;
 import net.pterodactylus.sone.template.CssClassNameFilter;
 import net.pterodactylus.sone.template.GetPagePlugin;
@@ -106,6 +109,15 @@ public class WebInterface implements CoreListener {
        /** The template factory. */
        private DefaultTemplateFactory templateFactory;
 
+       /** The “new Sone” notification. */
+       private final NewSoneNotification newSoneNotification;
+
+       /** The “new post” notification. */
+       private final NewPostNotification newPostNotification;
+
+       /** The “new reply” notification. */
+       private final NewReplyNotification newReplyNotification;
+
        /**
         * Creates a new web interface.
         *
@@ -135,6 +147,16 @@ public class WebInterface implements CoreListener {
                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);
+
+               Template newPostNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newPostNotification.html"));
+               newPostNotification = new NewPostNotification(newPostNotificationTemplate);
+
+               Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html"));
+               newReplyNotification = new NewReplyNotification(newReplyNotificationTemplate);
        }
 
        //
@@ -351,7 +373,8 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void newPostFound(Post post) {
-               /* TODO */
+               newPostNotification.addPost(post);
+               notificationManager.addNotification(newPostNotification);
        }
 
        /**
@@ -359,7 +382,41 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void newReplyFound(Reply reply) {
-               /* TODO */
+               newReplyNotification.addReply(reply);
+               notificationManager.addNotification(newReplyNotification);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void markSoneKnown(Sone sone) {
+               newSoneNotification.removeSone(sone);
+               if (newSoneNotification.isEmpty()) {
+                       newSoneNotification.dismiss();
+               }
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void markPostKnown(Post post) {
+               newPostNotification.removePost(post);
+               if (newPostNotification.isEmpty()) {
+                       newPostNotification.dismiss();
+               }
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void markReplyKnown(Reply reply) {
+               newReplyNotification.removeReply(reply);
+               if (newReplyNotification.isEmpty()) {
+                       newReplyNotification.dismiss();
+               }
        }
 
        /**