From: David ‘Bombe’ Roden Date: Fri, 6 May 2011 20:11:19 +0000 (+0200) Subject: Filter notifications differently. X-Git-Tag: 0.6.4^2~22 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f9c7e9ab57b4c85f1eaaf0de4c552a5d781659ec;p=Sone.git Filter notifications differently. --- diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java index 264e77c..2362d6a 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java @@ -50,28 +50,25 @@ public class ListNotificationFilters { * The current Sone, or {@code null} if not logged in * @return The filtered notifications */ - public static List filterNotifications(List notifications, Sone currentSone) { - ListNotification newPostNotification = getNotification(notifications, "new-post-notification", Post.class); - if (newPostNotification != null) { - ListNotification filteredNotification = filterNewPostNotification(newPostNotification, currentSone); - int notificationIndex = notifications.indexOf(newPostNotification); - if (filteredNotification == null) { - notifications.remove(notificationIndex); - } else { - notifications.set(notificationIndex, filteredNotification); - } - } - ListNotification newReplyNotification = getNotification(notifications, "new-replies-notification", Reply.class); - if (newReplyNotification != null) { - ListNotification filteredNotification = filterNewReplyNotification(newReplyNotification, currentSone); - int notificationIndex = notifications.indexOf(newReplyNotification); - if (filteredNotification == null) { - notifications.remove(notificationIndex); + @SuppressWarnings("unchecked") + public static List filterNotifications(Collection notifications, Sone currentSone) { + List filteredNotifications = new ArrayList(); + for (Notification notification : notifications) { + if (notification.getId().equals("new-post-notification")) { + ListNotification filteredNotification = filterNewPostNotification((ListNotification) notification, currentSone); + if (filteredNotification != null) { + filteredNotifications.add(filteredNotification); + } + } else if (notification.getId().equals("new-replies-notification")) { + ListNotification filteredNotification = filterNewReplyNotification((ListNotification) notification, currentSone); + if (filteredNotification != null) { + filteredNotifications.add(filteredNotification); + } } else { - notifications.set(notificationIndex, filteredNotification); + filteredNotifications.add(notification); } } - return notifications; + return filteredNotifications; } /** @@ -144,32 +141,6 @@ public class ListNotificationFilters { } /** - * Finds the notification with the given ID in the list of notifications and - * returns it. - * - * @param - * The type of the item in the notification - * @param notifications - * The notification to search - * @param notificationId - * The ID of the requested notification - * @param notificationElementClass - * The class of the notification item - * @return The requested notification, or {@code null} if no notification - * with the given ID could be found - */ - @SuppressWarnings("unchecked") - private static ListNotification getNotification(Collection notifications, String notificationId, Class notificationElementClass) { - for (Notification notification : notifications) { - if (!notificationId.equals(notification.getId())) { - continue; - } - return (ListNotification) notification; - } - return null; - } - - /** * Checks whether a post is visible to the given Sone. A post is not * considered visible if one of the following statements is true: *