Add notifications for Sones that are rescued.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 17 Nov 2010 20:46:12 +0000 (21:46 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 17 Nov 2010 20:46:12 +0000 (21:46 +0100)
src/main/java/net/pterodactylus/sone/core/CoreListener.java
src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/notify/rescuingSonesNotification.html [new file with mode: 0644]
src/main/resources/templates/notify/sonesRescuedNotification.html [new file with mode: 0644]

index ca99e87..595d11a 100644 (file)
@@ -32,6 +32,22 @@ import net.pterodactylus.sone.data.Sone;
 public interface CoreListener extends EventListener {
 
        /**
+        * Notifies a listener that a Sone is now being rescued.
+        *
+        * @param sone
+        *            The Sone that is rescued
+        */
+       public void rescuingSone(Sone sone);
+
+       /**
+        * Notifies a listener that the Sone was rescued and can now be unlocked.
+        *
+        * @param sone
+        *            The Sone that was rescued
+        */
+       public void rescuedSone(Sone sone);
+
+       /**
         * Notifies a listener that a new Sone has been discovered.
         *
         * @param sone
index 74838a1..0fd8b1a 100644 (file)
@@ -44,6 +44,32 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
+        * Notifies all listeners that the given Sone is now being rescued.
+        *
+        * @see CoreListener#rescuingSone(Sone)
+        * @param sone
+        *            The Sone that is being rescued
+        */
+       void fireRescuingSone(Sone sone) {
+               for (CoreListener coreListener : getListeners()) {
+                       coreListener.rescuingSone(sone);
+               }
+       }
+
+       /**
+        * Notifies all listeners that the given Sone was rescued.
+        *
+        * @see CoreListener#rescuedSone(Sone)
+        * @param sone
+        *            The Sone that was rescued
+        */
+       void fireRescuedSone(Sone sone) {
+               for (CoreListener coreListener : getListeners()) {
+                       coreListener.rescuedSone(sone);
+               }
+       }
+
+       /**
         * Notifies all listeners that a new Sone has been discovered.
         *
         * @see CoreListener#newSoneFound(Sone)
index 747b192..441e323 100644 (file)
@@ -119,6 +119,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 +164,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);
        }
 
        //
@@ -387,6 +399,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);
index efd6c76..a412903 100644 (file)
@@ -173,3 +173,7 @@ Notification.Button.Dismiss=Dismiss
 Notification.NewSone.Text=New Sones have been discovered:
 Notification.NewPost.Text=New posts have been discovered by the following Sones:
 Notification.NewReply.Text=New replies have been discovered by the following Sones:
+Notification.SoneIsBeingRescued.Text=The following Sones are currently being rescued:
+Notification.SoneRescued.Text=The following Sones have been rescued:
+Notification.SoneRescued.Text.RememberToUnlock=Please remember to control the posts and replies you have given and don’t forget to unlock your Sones!
+
diff --git a/src/main/resources/templates/notify/rescuingSonesNotification.html b/src/main/resources/templates/notify/rescuingSonesNotification.html
new file mode 100644 (file)
index 0000000..eef06ac
--- /dev/null
@@ -0,0 +1,6 @@
+<div class="text">
+       <%= Notification.SoneIsBeingRescued.Text|l10n|html>
+       <%foreach sones sone>
+               <a href="viewSone.html?sone=<% sone.id|html>" title="<% sone.requestUri|html>"><% sone.niceName|html></a><%notlast>,<%/notlast><%last>.<%/last>
+       <%/foreach>
+</div>
diff --git a/src/main/resources/templates/notify/sonesRescuedNotification.html b/src/main/resources/templates/notify/sonesRescuedNotification.html
new file mode 100644 (file)
index 0000000..84f015d
--- /dev/null
@@ -0,0 +1,7 @@
+<div class="text">
+       <%= Notification.SoneRescued.Text|l10n|html>
+       <%foreach sones sone>
+               <a href="viewSone.html?sone=<% sone.id|html>" title="<% sone.requestUri|html>"><% sone.niceName|html></a><%notlast>,<%/notlast><%last>.<%/last>
+       <%/foreach>
+       <%= Notification.SoneRescued.Text.RememberToUnlock|l10n|html>
+</div>