From: David ‘Bombe’ Roden Date: Fri, 15 Jul 2011 04:39:37 +0000 (+0200) Subject: Allow filtering notifications without a current Sone. X-Git-Tag: 0.6.6^2~16 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=012439f891860c345b6bcab68e663bdd93c9aeb5 Allow filtering notifications without a current Sone. --- diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java index 52f85ba..3db8912 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java @@ -55,7 +55,7 @@ public class ListNotificationFilters { List filteredNotifications = new ArrayList(); for (Notification notification : notifications) { if (notification.getId().equals("new-post-notification")) { - ListNotification filteredNotification = filterNewPostNotification((ListNotification) notification, currentSone); + ListNotification filteredNotification = filterNewPostNotification((ListNotification) notification, currentSone, true); if (filteredNotification != null) { filteredNotifications.add(filteredNotification); } @@ -65,7 +65,7 @@ public class ListNotificationFilters { filteredNotifications.add(filteredNotification); } } else if (notification.getId().equals("mention-notification")) { - ListNotification filteredNotification = filterNewPostNotification((ListNotification) notification, null); + ListNotification filteredNotification = filterNewPostNotification((ListNotification) notification, null, false); if (filteredNotification != null) { filteredNotifications.add(filteredNotification); } @@ -78,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 filterNewPostNotification(ListNotification newPostNotification, Sone currentSone) { - if (currentSone == null) { + public static ListNotification filterNewPostNotification(ListNotification newPostNotification, Sone currentSone, boolean soneRequired) { + if (soneRequired && (currentSone == null)) { return null; } List newPosts = new ArrayList(); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java index 03cecee..34770c6 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java @@ -82,7 +82,7 @@ public class GetNotificationAjaxPage extends JsonPage { for (String notificationId : notificationIds) { Notification notification = webInterface.getNotifications().getNotification(notificationId); if ("new-post-notification".equals(notificationId)) { - notification = ListNotificationFilters.filterNewPostNotification((ListNotification) notification, currentSone); + notification = ListNotificationFilters.filterNewPostNotification((ListNotification) notification, currentSone, false); } else if ("new-reply-notification".equals(notificationId)) { notification = ListNotificationFilters.filterNewReplyNotification((ListNotification) notification, currentSone); }