- public static List<Notification> filterNotifications(List<Notification> notifications, Sone currentSone) {
- ListNotification<Post> newPostNotification = getNotification(notifications, "new-post-notification", Post.class);
- if (newPostNotification != null) {
- ListNotification<Post> filteredNotification = filterNewPostNotification(newPostNotification, currentSone);
- int notificationIndex = notifications.indexOf(newPostNotification);
- if (filteredNotification == null) {
- notifications.remove(notificationIndex);
- } else {
- notifications.set(notificationIndex, filteredNotification);
- }
- }
- ListNotification<Reply> newReplyNotification = getNotification(notifications, "new-replies-notification", Reply.class);
- if (newReplyNotification != null) {
- ListNotification<Reply> filteredNotification = filterNewReplyNotification(newReplyNotification, currentSone);
- int notificationIndex = notifications.indexOf(newReplyNotification);
- if (filteredNotification == null) {
- notifications.remove(notificationIndex);
+ @SuppressWarnings("unchecked")
+ 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-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);
+ }
+ } else if (notification.getId().equals("mention-notification")) {
+ ListNotification<Post> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, null, false);
+ if (filteredNotification != null) {
+ filteredNotifications.add(filteredNotification);
+ }