+ * 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.
+ *
+ * @param newPostNotification
+ * The new-post notification
+ * @param currentSone
+ * The current Sone, or {@code null} if not logged in
+ * @return The filtered new-post notification, or {@code null} if the
+ * notification should be removed
+ */
+ private static ListNotification<Post> filterNewPostNotification(ListNotification<Post> newPostNotification, Sone currentSone) {
+ if (currentSone == null) {
+ return null;
+ }
+ List<Post> newPosts = new ArrayList<Post>();
+ for (Post post : newPostNotification.getElements()) {
+ if (currentSone.hasFriend(post.getSone().getId()) || currentSone.equals(post.getSone()) || currentSone.equals(post.getRecipient())) {
+ newPosts.add(post);
+ }
+ }
+ if (newPosts.isEmpty()) {
+ return null;
+ }
+ if (newPosts.size() == newPostNotification.getElements().size()) {
+ return newPostNotification;
+ }
+ ListNotification<Post> filteredNotification = new ListNotification<Post>(newPostNotification);
+ filteredNotification.setElements(newPosts);
+ return 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 static ListNotification<Reply> filterNewReplyNotification(ListNotification<Reply> newReplyNotification, Sone currentSone) {
+ if (currentSone == null) {
+ return null;
+ }
+ List<Reply> newReplies = new ArrayList<Reply>();
+ for (Reply reply : newReplyNotification.getElements()) {
+ if (currentSone.hasFriend(reply.getPost().getSone().getId()) || currentSone.equals(reply.getPost().getSone()) || currentSone.equals(reply.getPost().getRecipient())) {
+ newReplies.add(reply);
+ }
+ }
+ if (newReplies.isEmpty()) {
+ return null;
+ }
+ if (newReplies.size() == newReplyNotification.getElements().size()) {
+ return newReplyNotification;
+ }
+ ListNotification<Reply> filteredNotification = new ListNotification<Reply>(newReplyNotification);
+ filteredNotification.setElements(newReplies);
+ return filteredNotification;
+ }
+
+ /**