Don’t render posts and replies on getStatus().
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index db1880b..a7b6728 100644 (file)
@@ -21,11 +21,11 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -54,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;
@@ -119,6 +118,12 @@ public class WebInterface implements CoreListener {
        /** The “new reply” notification. */
        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.
         *
@@ -158,6 +163,12 @@ public class WebInterface implements CoreListener {
 
                Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html"));
                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);
        }
 
        //
@@ -197,12 +208,7 @@ public class WebInterface implements CoreListener {
         * @return The node’s session manager
         */
        public SessionManager getSessionManager() {
-               try {
-                       return sonePlugin.pluginRespirator().getSessionManager(new URI("/"));
-               } catch (URISyntaxException use1) {
-                       logger.log(Level.SEVERE, "Could not get Session Manager!", use1);
-                       return null;
-               }
+               return sonePlugin.pluginRespirator().getSessionManager("Sone");
        }
 
        /**
@@ -214,6 +220,26 @@ public class WebInterface implements CoreListener {
                return formPassword;
        }
 
+       /**
+        * Returns the posts that have been announced as new in the
+        * {@link #newPostNotification}.
+        *
+        * @return The new posts
+        */
+       public Set<Post> getNewPosts() {
+               return new HashSet<Post>(newPostNotification.getElements());
+       }
+
+       /**
+        * Returns the replies that have been announced as new in the
+        * {@link #newReplyNotification}.
+        *
+        * @return The new replies
+        */
+       public Set<Reply> getNewReplies() {
+               return new HashSet<Reply>(newReplyNotification.getElements());
+       }
+
        //
        // ACTIONS
        //
@@ -295,6 +321,7 @@ public class WebInterface implements CoreListener {
                Template logoutTemplate = templateFactory.createTemplate(createReader("/templates/logout.html"));
                Template optionsTemplate = templateFactory.createTemplate(createReader("/templates/options.html"));
                Template aboutTemplate = templateFactory.createTemplate(createReader("/templates/about.html"));
+               Template postTemplate = templateFactory.createTemplate(createReader("/templates/include/viewPost.html"));
                Template replyTemplate = templateFactory.createTemplate(createReader("/templates/include/viewReply.html"));
 
                PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
@@ -325,9 +352,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)));
@@ -387,6 +413,25 @@ 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.add(sone);
                notificationManager.addNotification(newSoneNotification);
@@ -419,9 +464,6 @@ public class WebInterface implements CoreListener {
        @Override
        public void markSoneKnown(Sone sone) {
                newSoneNotification.remove(sone);
-               if (newSoneNotification.isEmpty()) {
-                       newSoneNotification.dismiss();
-               }
        }
 
        /**
@@ -430,9 +472,6 @@ public class WebInterface implements CoreListener {
        @Override
        public void markPostKnown(Post post) {
                newPostNotification.remove(post);
-               if (newPostNotification.isEmpty()) {
-                       newPostNotification.dismiss();
-               }
        }
 
        /**
@@ -441,9 +480,6 @@ public class WebInterface implements CoreListener {
        @Override
        public void markReplyKnown(Reply reply) {
                newReplyNotification.remove(reply);
-               if (newReplyNotification.isEmpty()) {
-                       newReplyNotification.dismiss();
-               }
        }
 
        /**