Use template factory to create templates.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index 5865f1d..dc573ca 100644 (file)
@@ -255,7 +255,7 @@ public class WebInterface implements CoreListener {
         */
        public void setFirstStart(boolean firstStart) {
                if (firstStart) {
-                       Template firstStartNotificationTemplate = new Template(createReader("/templates/notify/firstStartNotification.html"));
+                       Template firstStartNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/firstStartNotification.html"));
                        Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
                        notificationManager.addNotification(firstStartNotification);
                }
@@ -269,14 +269,28 @@ public class WebInterface implements CoreListener {
         *            {@code false} if the existing configuration could be read
         */
        public void setNewConfig(boolean newConfig) {
-               if (newConfig && (notificationManager.getNotification("first-start-notification") == null)) {
-                       Template configNotReadNotificationTemplate = new Template(createReader("/templates/notify/configNotReadNotification.html"));
+               if (newConfig && !hasFirstStartNotification()) {
+                       Template configNotReadNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/configNotReadNotification.html"));
                        Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
                        notificationManager.addNotification(configNotReadNotification);
                }
        }
 
        //
+       // PRIVATE ACCESSORS
+       //
+
+       /**
+        * Returns whether the first start notification is currently displayed.
+        *
+        * @return {@code true} if the first-start notification is currently
+        *         displayed, {@code false} otherwise
+        */
+       private boolean hasFirstStartNotification() {
+               return notificationManager.getNotification("first-start-notification") != null;
+       }
+
+       //
        // ACTIONS
        //
 
@@ -474,7 +488,9 @@ public class WebInterface implements CoreListener {
        @Override
        public void newSoneFound(Sone sone) {
                newSoneNotification.add(sone);
-               notificationManager.addNotification(newSoneNotification);
+               if (!hasFirstStartNotification()) {
+                       notificationManager.addNotification(newSoneNotification);
+               }
        }
 
        /**
@@ -483,7 +499,9 @@ public class WebInterface implements CoreListener {
        @Override
        public void newPostFound(Post post) {
                newPostNotification.add(post);
-               notificationManager.addNotification(newPostNotification);
+               if (!hasFirstStartNotification()) {
+                       notificationManager.addNotification(newPostNotification);
+               }
        }
 
        /**
@@ -495,7 +513,9 @@ public class WebInterface implements CoreListener {
                        return;
                }
                newReplyNotification.add(reply);
-               notificationManager.addNotification(newReplyNotification);
+               if (!hasFirstStartNotification()) {
+                       notificationManager.addNotification(newReplyNotification);
+               }
        }
 
        /**