Merge branch 'configurable-notifications-250' into next
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 11 Nov 2011 12:24:57 +0000 (13:24 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 11 Nov 2011 12:26:04 +0000 (13:26 +0100)
This resolves #250.

Conflicts:
src/main/java/net/pterodactylus/sone/core/Core.java

src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java
src/main/java/net/pterodactylus/sone/web/OptionsPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java
src/main/resources/i18n/sone.en.properties
src/main/resources/static/javascript/sone.js
src/main/resources/templates/options.html

index d24f497..264390e 100644 (file)
@@ -1009,6 +1009,9 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                Sone sone = addLocalSone(ownIdentity);
                sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption<Boolean>(false));
                sone.getOptions().addBooleanOption("EnableSoneInsertNotifications", new DefaultOption<Boolean>(false));
+               sone.getOptions().addBooleanOption("ShowNotification/NewSones", new DefaultOption<Boolean>(true));
+               sone.getOptions().addBooleanOption("ShowNotification/NewPosts", new DefaultOption<Boolean>(true));
+               sone.getOptions().addBooleanOption("ShowNotification/NewReplies", new DefaultOption<Boolean>(true));
                sone.addFriend("nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI");
                touchConfiguration();
                return sone;
@@ -1344,6 +1347,9 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                /* initialize options. */
                sone.getOptions().addBooleanOption("AutoFollow", new DefaultOption<Boolean>(false));
                sone.getOptions().addBooleanOption("EnableSoneInsertNotifications", new DefaultOption<Boolean>(false));
+               sone.getOptions().addBooleanOption("ShowNotification/NewSones", new DefaultOption<Boolean>(true));
+               sone.getOptions().addBooleanOption("ShowNotification/NewPosts", new DefaultOption<Boolean>(true));
+               sone.getOptions().addBooleanOption("ShowNotification/NewReplies", new DefaultOption<Boolean>(true));
 
                /* load Sone. */
                String sonePrefix = "Sone/" + sone.getId();
@@ -2132,6 +2138,9 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
 
                        /* save options. */
                        configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().getBooleanOption("AutoFollow").getReal());
+                       configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewSones").setValue(sone.getOptions().getBooleanOption("ShowNotification/NewSones").getReal());
+                       configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewPosts").setValue(sone.getOptions().getBooleanOption("ShowNotification/NewPosts").getReal());
+                       configuration.getBooleanValue(sonePrefix + "/Options/ShowNotification/NewReplies").setValue(sone.getOptions().getBooleanOption("ShowNotification/NewReplies").getReal());
                        configuration.getBooleanValue(sonePrefix + "/Options/EnableSoneInsertNotifications").setValue(sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").getReal());
 
                        configuration.save();
index beeb81e..7b9eb49 100644 (file)
@@ -55,12 +55,23 @@ public class ListNotificationFilters {
        public static List<Notification> filterNotifications(Collection<? extends Notification> notifications, Sone currentSone) {
                List<Notification> filteredNotifications = new ArrayList<Notification>();
                for (Notification notification : notifications) {
-                       if (notification.getId().equals("new-post-notification")) {
+                       if (notification.getId().equals("new-sone-notification")) {
+                               if ((currentSone != null) && (!currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get())) {
+                                       continue;
+                               }
+                               filteredNotifications.add(notification);
+                       } else if (notification.getId().equals("new-post-notification")) {
+                               if ((currentSone != null) && (!currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get())) {
+                                       continue;
+                               }
                                ListNotification<Post> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, currentSone, true);
                                if (filteredNotification != null) {
                                        filteredNotifications.add(filteredNotification);
                                }
                        } else if (notification.getId().equals("new-reply-notification")) {
+                               if ((currentSone != null) && (!currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get())) {
+                                       continue;
+                               }
                                ListNotification<PostReply> filteredNotification = filterNewReplyNotification((ListNotification<PostReply>) notification, currentSone);
                                if (filteredNotification != null) {
                                        filteredNotifications.add(filteredNotification);
index 7b4a634..49b1275 100644 (file)
@@ -67,6 +67,12 @@ public class OptionsPage extends SoneTemplatePage {
                                currentSone.getOptions().getBooleanOption("AutoFollow").set(autoFollow);
                                boolean enableSoneInsertNotifications = request.getHttpRequest().isPartSet("enable-sone-insert-notifications");
                                currentSone.getOptions().getBooleanOption("EnableSoneInsertNotifications").set(enableSoneInsertNotifications);
+                               boolean showNotificationNewSones = request.getHttpRequest().isPartSet("show-notification-new-sones");
+                               currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").set(showNotificationNewSones);
+                               boolean showNotificationNewPosts = request.getHttpRequest().isPartSet("show-notification-new-posts");
+                               currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").set(showNotificationNewPosts);
+                               boolean showNotificationNewReplies = request.getHttpRequest().isPartSet("show-notification-new-replies");
+                               currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").set(showNotificationNewReplies);
                                webInterface.getCore().touchConfiguration();
                        }
                        Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16));
@@ -130,6 +136,9 @@ public class OptionsPage extends SoneTemplatePage {
                if (currentSone != null) {
                        templateContext.set("auto-follow", currentSone.getOptions().getBooleanOption("AutoFollow").get());
                        templateContext.set("enable-sone-insert-notifications", currentSone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get());
+                       templateContext.set("show-notification-new-sones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
+                       templateContext.set("show-notification-new-posts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
+                       templateContext.set("show-notification-new-replies", currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
                }
                templateContext.set("insertion-delay", preferences.getInsertionDelay());
                templateContext.set("posts-per-page", preferences.getPostsPerPage());
index 038cfb8..5f2103a 100644 (file)
@@ -145,7 +145,7 @@ public class GetStatusAjaxPage extends JsonPage {
                        jsonReply.put("postSone", reply.getPost().getSone().getId());
                        jsonReplies.add(jsonReply);
                }
-               return createSuccessJsonObject().put("loggedIn", currentSone != null).put("sones", jsonSones).put("notifications", jsonNotificationInformations).put("newPosts", jsonPosts).put("newReplies", jsonReplies);
+               return createSuccessJsonObject().put("loggedIn", currentSone != null).put("options", createJsonOptions(currentSone)).put("sones", jsonSones).put("notifications", jsonNotificationInformations).put("newPosts", jsonPosts).put("newReplies", jsonReplies);
        }
 
        /**
@@ -209,4 +209,23 @@ public class GetStatusAjaxPage extends JsonPage {
                return jsonNotification;
        }
 
+       /**
+        * Creates a JSON object that contains all options that are currently in
+        * effect for the given Sone (or overall, if the given Sone is {@code null}
+        * ).
+        *
+        * @param currentSone
+        *            The current Sone (may be {@code null})
+        * @return The current options
+        */
+       private JsonObject createJsonOptions(Sone currentSone) {
+               JsonObject options = new JsonObject();
+               if (currentSone != null) {
+                       options.put("ShowNotification/NewSones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
+                       options.put("ShowNotification/NewPosts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
+                       options.put("ShowNotification/NewReplies", currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
+               }
+               return options;
+       }
+
 }
index 4210930..fb592df 100644 (file)
@@ -40,6 +40,9 @@ Page.Options.Section.SoneSpecificOptions.NotLoggedIn=These options are only avai
 Page.Options.Section.SoneSpecificOptions.LoggedIn=These options are only available while you are logged in and they are only valid for the Sone you are logged in as.
 Page.Options.Option.AutoFollow.Description=If a new Sone is discovered, follow it automatically. Note that this will only follow Sones that are discovered after you activate this option!
 Page.Options.Option.EnableSoneInsertNotifications.Description=If enabled, this will display notifications every time your Sone is being inserted or finishes inserting.
+Page.Options.Option.ShowNotificationNewSones.Description=Show notifications for new Sones.
+Page.Options.Option.ShowNotificationNewPosts.Description=Show notifications for new posts.
+Page.Options.Option.ShowNotificationNewReplies.Description=Show notifications for new replies.
 Page.Options.Section.RuntimeOptions.Title=Runtime Behaviour
 Page.Options.Option.InsertionDelay.Description=The number of seconds the Sone inserter waits after a modification of a Sone before it is being inserted.
 Page.Options.Option.PostsPerPage.Description=The number of posts to display on a page before pagination controls are being shown.
index bbd039c..b819333 100644 (file)
@@ -1193,17 +1193,17 @@ function getStatus() {
                                        }
                                });
                                if (!foundNotification) {
-                                       if (notificationId == "new-sone-notification") {
+                                       if (notificationId == "new-sone-notification" && (data.options["ShowNotification/NewSones"] == true)) {
                                                $(".new-sone-id", this).each(function(index, element) {
                                                        soneId = $(this).text();
                                                        markSoneAsKnown(getSone(soneId), true);
                                                });
-                                       } else if (notificationId == "new-post-notification") {
+                                       } else if (notificationId == "new-post-notification" && (data.options["ShowNotification/NewPosts"] == true)) {
                                                $(".post-id", this).each(function(index, element) {
                                                        postId = $(this).text();
                                                        markPostAsKnown(getPost(postId), true);
                                                });
-                                       } else if (notificationId == "new-reply-notification") {
+                                       } else if (notificationId == "new-reply-notification" && (data.options["ShowNotification/NewReplies"] == true)) {
                                                $(".reply-id", this).each(function(index, element) {
                                                        replyId = $(this).text();
                                                        markReplyAsKnown(getReply(replyId), true);
index 2adf57e..57f3c5f 100644 (file)
                        <%= Page.Options.Option.EnableSoneInsertNotifications.Description|l10n|html>
                </p>
 
+               <p>
+                       <input type="checkbox" name="show-notification-new-sones"<%ifnull currentSone> disabled="disabled"<%/if><%if show-notification-new-sones> checked="checked"<%/if>/>
+                       <%= Page.Options.Option.ShowNotificationNewSones.Description|l10n|html>
+               </p>
+
+               <p>
+                       <input type="checkbox" name="show-notification-new-posts"<%ifnull currentSone> disabled="disabled"<%/if><%if show-notification-new-posts> checked="checked"<%/if>/>
+                       <%= Page.Options.Option.ShowNotificationNewPosts.Description|l10n|html>
+               </p>
+
+               <p>
+                       <input type="checkbox" name="show-notification-new-replies"<%ifnull currentSone> disabled="disabled"<%/if><%if show-notification-new-replies> checked="checked"<%/if>/>
+                       <%= Page.Options.Option.ShowNotificationNewReplies.Description|l10n|html>
+               </p>
+
                <h2><%= Page.Options.Section.RuntimeOptions.Title|l10n|html></h2>
 
                <p><%= Page.Options.Option.InsertionDelay.Description|l10n|html></p>