Merge branch 'next' into dev/image
[Sone.git] / src / main / java / net / pterodactylus / sone / notify / ListNotificationFilters.java
index 908ea2b..3db8912 100644 (file)
@@ -54,8 +54,8 @@ 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") || notification.getId().equals("mention-notification")) {
-                               ListNotification<Post> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, currentSone);
+                       if (notification.getId().equals("new-post-notification")) {
+                               ListNotification<Post> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, currentSone, true);
                                if (filteredNotification != null) {
                                        filteredNotifications.add(filteredNotification);
                                }
@@ -64,6 +64,11 @@ public class ListNotificationFilters {
                                if (filteredNotification != null) {
                                        filteredNotifications.add(filteredNotification);
                                }
+                       } else if (notification.getId().equals("mention-notification")) {
+                               ListNotification<Post> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, null, false);
+                               if (filteredNotification != null) {
+                                       filteredNotifications.add(filteredNotification);
+                               }
                        } else {
                                filteredNotifications.add(notification);
                        }
@@ -73,19 +78,23 @@ public class ListNotificationFilters {
 
        /**
         * Filters the new posts of the given notification. If {@code currentSone}
-        * is {@code null}, {@code null} is returned and the notification is
-        * subsequently removed. Otherwise only posts that are posted by friend
-        * Sones of the given Sone are retained; all other posts are removed.
+        * is {@code null} and {@code soneRequired} is {@code true}, {@code null} is
+        * returned and the notification is subsequently removed. Otherwise only
+        * posts that are posted by friend Sones of the given Sone are retained; all
+        * other posts are removed.
         *
         * @param newPostNotification
         *            The new-post notification
         * @param currentSone
         *            The current Sone, or {@code null} if not logged in
+        * @param soneRequired
+        *            Whether a non-{@code null} Sone in {@code currentSone} is
+        *            required
         * @return The filtered new-post notification, or {@code null} if the
         *         notification should be removed
         */
-       public static ListNotification<Post> filterNewPostNotification(ListNotification<Post> newPostNotification, Sone currentSone) {
-               if (currentSone == null) {
+       public static ListNotification<Post> filterNewPostNotification(ListNotification<Post> newPostNotification, Sone currentSone, boolean soneRequired) {
+               if (soneRequired && (currentSone == null)) {
                        return null;
                }
                List<Post> newPosts = new ArrayList<Post>();