- 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 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().isShowNewSoneNotifications()) {
+ continue;
+ }
+ filteredNotifications.add(notification);
+ } else if (notification.getId().equals("new-post-notification")) {
+ if (currentSone == null) {
+ continue;
+ }
+ if (!currentSone.getOptions().isShowNewPostNotifications()) {
+ continue;
+ }
+ Optional<ListNotification<Post>> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, currentSone);
+ if (filteredNotification.isPresent()) {
+ filteredNotifications.add(filteredNotification.get());
+ }
+ } else if (notification.getId().equals("new-reply-notification")) {
+ if (currentSone == null) {
+ continue;
+ }
+ if (!currentSone.getOptions().isShowNewReplyNotifications()) {
+ continue;
+ }
+ Optional<ListNotification<PostReply>> filteredNotification =
+ filterNewReplyNotification((ListNotification<PostReply>) notification, currentSone);
+ if (filteredNotification.isPresent()) {
+ filteredNotifications.add(filteredNotification.get());
+ }
+ } else if (notification.getId().equals("mention-notification")) {
+ Optional<ListNotification<Post>> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, null);
+ if (filteredNotification.isPresent()) {
+ filteredNotifications.add(filteredNotification.get());
+ }