Replace getSoneStatus and getNotifications with getStatus.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index e16ca9d..31f9f0d 100644 (file)
@@ -37,9 +37,7 @@ 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.notify.ListNotification;
 import net.pterodactylus.sone.template.CollectionAccessor;
 import net.pterodactylus.sone.template.CssClassNameFilter;
 import net.pterodactylus.sone.template.GetPagePlugin;
@@ -56,9 +54,8 @@ import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
 import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage;
 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
-import net.pterodactylus.sone.web.ajax.GetNotificationsAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
-import net.pterodactylus.sone.web.ajax.GetSoneStatusPage;
+import net.pterodactylus.sone.web.ajax.GetStatusAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetTranslationPage;
 import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
 import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
@@ -113,13 +110,19 @@ public class WebInterface implements CoreListener {
        private DefaultTemplateFactory templateFactory;
 
        /** The “new Sone” notification. */
-       private final NewSoneNotification newSoneNotification;
+       private final ListNotification<Sone> newSoneNotification;
 
        /** The “new post” notification. */
-       private final NewPostNotification newPostNotification;
+       private final ListNotification<Post> newPostNotification;
 
        /** The “new reply” notification. */
-       private final NewReplyNotification newReplyNotification;
+       private final ListNotification<Reply> newReplyNotification;
+
+       /** The “rescuing Sone” notification. */
+       private final ListNotification<Sone> rescuingSonesNotification;
+
+       /** The “Sone rescued” notification. */
+       private final ListNotification<Sone> sonesRescuedNotification;
 
        /**
         * Creates a new web interface.
@@ -153,13 +156,19 @@ public class WebInterface implements CoreListener {
 
                /* create notifications. */
                Template newSoneNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newSoneNotification.html"));
-               newSoneNotification = new NewSoneNotification(newSoneNotificationTemplate);
+               newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate);
 
                Template newPostNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newPostNotification.html"));
-               newPostNotification = new NewPostNotification(newPostNotificationTemplate);
+               newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate);
 
                Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html"));
-               newReplyNotification = new NewReplyNotification(newReplyNotificationTemplate);
+               newReplyNotification = new ListNotification<Reply>("new-replies-notification", "replies", newReplyNotificationTemplate);
+
+               Template rescuingSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/rescuingSonesNotification.html"));
+               rescuingSonesNotification = new ListNotification<Sone>("sones-being-rescued-notification", "sones", rescuingSonesTemplate);
+
+               Template sonesRescuedTemplate = templateFactory.createTemplate(createReader("/templates/notify/sonesRescuedNotification.html"));
+               sonesRescuedNotification = new ListNotification<Sone>("sones-rescued-notification", "sones", sonesRescuedTemplate);
        }
 
        //
@@ -327,9 +336,8 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript")));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png")));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
-               pageToadlets.add(pageToadletFactory.createPageToadlet(new GetNotificationsAjaxPage(this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
-               pageToadlets.add(pageToadletFactory.createPageToadlet(new GetSoneStatusPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
@@ -389,8 +397,27 @@ public class WebInterface implements CoreListener {
         * {@inheritDoc}
         */
        @Override
+       public void rescuingSone(Sone sone) {
+               rescuingSonesNotification.add(sone);
+               notificationManager.addNotification(rescuingSonesNotification);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void rescuedSone(Sone sone) {
+               rescuingSonesNotification.remove(sone);
+               sonesRescuedNotification.add(sone);
+               notificationManager.addNotification(sonesRescuedNotification);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
        public void newSoneFound(Sone sone) {
-               newSoneNotification.addSone(sone);
+               newSoneNotification.add(sone);
                notificationManager.addNotification(newSoneNotification);
        }
 
@@ -399,7 +426,7 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void newPostFound(Post post) {
-               newPostNotification.addPost(post);
+               newPostNotification.add(post);
                notificationManager.addNotification(newPostNotification);
        }
 
@@ -411,7 +438,7 @@ public class WebInterface implements CoreListener {
                if (reply.getPost().getSone() == null) {
                        return;
                }
-               newReplyNotification.addReply(reply);
+               newReplyNotification.add(reply);
                notificationManager.addNotification(newReplyNotification);
        }
 
@@ -420,10 +447,7 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void markSoneKnown(Sone sone) {
-               newSoneNotification.removeSone(sone);
-               if (newSoneNotification.isEmpty()) {
-                       newSoneNotification.dismiss();
-               }
+               newSoneNotification.remove(sone);
        }
 
        /**
@@ -431,10 +455,7 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void markPostKnown(Post post) {
-               newPostNotification.removePost(post);
-               if (newPostNotification.isEmpty()) {
-                       newPostNotification.dismiss();
-               }
+               newPostNotification.remove(post);
        }
 
        /**
@@ -442,10 +463,7 @@ public class WebInterface implements CoreListener {
         */
        @Override
        public void markReplyKnown(Reply reply) {
-               newReplyNotification.removeReply(reply);
-               if (newReplyNotification.isEmpty()) {
-                       newReplyNotification.dismiss();
-               }
+               newReplyNotification.remove(reply);
        }
 
        /**