/*
- * Sone - ListNotificationFilters.java - Copyright © 2010–2015 David Roden
+ * Sone - ListNotificationFilter.java - Copyright © 2010–2019 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import java.util.Collection;
import java.util.List;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* Filter for {@link ListNotification}s.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
@Singleton
public class ListNotificationFilter {
*/
@SuppressWarnings("unchecked")
public List<Notification> filterNotifications(Collection<? extends Notification> notifications, Sone currentSone) {
- List<Notification> filteredNotifications = new ArrayList<Notification>();
+ List<Notification> filteredNotifications = new ArrayList<>();
for (Notification notification : notifications) {
if (notification.getId().equals("new-sone-notification")) {
if ((currentSone != null) && !currentSone.getOptions().isShowNewSoneNotifications()) {
if (!currentSone.getOptions().isShowNewPostNotifications()) {
continue;
}
- Optional<ListNotification<Post>> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, currentSone);
+ Optional<ListNotification<Post>> filteredNotification = filterPostNotification((ListNotification<Post>) notification, currentSone);
if (filteredNotification.isPresent()) {
filteredNotifications.add(filteredNotification.get());
}
filteredNotifications.add(filteredNotification.get());
}
} else if (notification.getId().equals("mention-notification")) {
- Optional<ListNotification<Post>> filteredNotification = filterNewPostNotification((ListNotification<Post>) notification, null);
+ Optional<ListNotification<Post>> filteredNotification = filterPostNotification((ListNotification<Post>) notification, null);
if (filteredNotification.isPresent()) {
filteredNotifications.add(filteredNotification.get());
}
}
/**
- * Filters the new posts of the given notification. If {@code currentSone}
- * is {@code null} and {@code soneRequired} is {@code true}, {@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.
+ * Filters the posts of the given notification.
*
- * @param newPostNotification
- * The new-post notification
+ * @param postNotification
+ * The 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
+ * @return The filtered post notification, or {@link Optional#absent()} if the notification should be removed
*/
@Nonnull
- private Optional<ListNotification<Post>> filterNewPostNotification(@Nonnull ListNotification<Post> newPostNotification,
- @Nonnull Sone currentSone) {
- List<Post> newPosts = from(newPostNotification.getElements()).filter(postVisibilityFilter.isVisible(currentSone)).toList();
+ private Optional<ListNotification<Post>> filterPostNotification(@Nonnull ListNotification<Post> postNotification,
+ @Nullable Sone currentSone) {
+ List<Post> newPosts = from(postNotification.getElements()).filter(postVisibilityFilter.isVisible(currentSone)).toList();
if (newPosts.isEmpty()) {
return Optional.absent();
}
- if (newPosts.size() == newPostNotification.getElements().size()) {
- return Optional.of(newPostNotification);
+ if (newPosts.size() == postNotification.getElements().size()) {
+ return Optional.of(postNotification);
}
- ListNotification<Post> filteredNotification = new ListNotification<Post>(newPostNotification);
+ ListNotification<Post> filteredNotification = new ListNotification<>(postNotification);
filteredNotification.setElements(newPosts);
- filteredNotification.setLastUpdateTime(newPostNotification.getLastUpdatedTime());
+ filteredNotification.setLastUpdateTime(postNotification.getLastUpdatedTime());
return Optional.of(filteredNotification);
}
if (newReplies.size() == newReplyNotification.getElements().size()) {
return Optional.of(newReplyNotification);
}
- ListNotification<PostReply> filteredNotification = new ListNotification<PostReply>(newReplyNotification);
+ ListNotification<PostReply> filteredNotification = new ListNotification<>(newReplyNotification);
filteredNotification.setElements(newReplies);
filteredNotification.setLastUpdateTime(newReplyNotification.getLastUpdatedTime());
return Optional.of(filteredNotification);