- @SuppressWarnings("unchecked")
- private static <T> ListNotification<T> getNotification(Collection<? extends Notification> notifications, String notificationId, Class<T> notificationElementClass) {
- for (Notification notification : notifications) {
- if (!notificationId.equals(notification.getId())) {
- continue;
- }
- return (ListNotification<T>) notification;
+ @Nonnull
+ private Optional<ListNotification<Post>> filterNewPostNotification(@Nonnull ListNotification<Post> newPostNotification,
+ @Nonnull Sone currentSone) {
+ List<Post> newPosts = from(newPostNotification.getElements()).filter(postVisibilityFilter.isVisible(currentSone)).toList();
+ if (newPosts.isEmpty()) {
+ return Optional.absent();
+ }
+ if (newPosts.size() == newPostNotification.getElements().size()) {
+ return Optional.of(newPostNotification);
+ }
+ ListNotification<Post> filteredNotification = new ListNotification<Post>(newPostNotification);
+ filteredNotification.setElements(newPosts);
+ filteredNotification.setLastUpdateTime(newPostNotification.getLastUpdatedTime());
+ return Optional.of(filteredNotification);
+ }
+
+ /**
+ * Filters the new replies of the given notification. If {@code currentSone}
+ * is {@code null}, {@code null} is returned and the notification is
+ * subsequently removed. Otherwise only replies that are replies to posts
+ * that are posted by friend Sones of the given Sone are retained; all other
+ * replies are removed.
+ *
+ * @param newReplyNotification
+ * The new-reply notification
+ * @param currentSone
+ * The current Sone, or {@code null} if not logged in
+ * @return The filtered new-reply notification, or {@code null} if the
+ * notification should be removed
+ */
+ private Optional<ListNotification<PostReply>> filterNewReplyNotification(ListNotification<PostReply> newReplyNotification,
+ @Nonnull Sone currentSone) {
+ List<PostReply> newReplies = from(newReplyNotification.getElements()).filter(replyVisibilityFilter.isVisible(currentSone)).toList();
+ if (newReplies.isEmpty()) {
+ return Optional.absent();
+ }
+ if (newReplies.size() == newReplyNotification.getElements().size()) {
+ return Optional.of(newReplyNotification);