X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FListNotificationFilter.java;h=739907cc04607ffe66c3e15f2741a26b90c33036;hb=3b744b825c91ea77c619a6fd7b9855fa0f6fbd3e;hp=77dc2eaf898f1c231363f3e4315d3e763a178472;hpb=64ed0712bbfba30577c8df20bfac6bb25e6606b2;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java
index 77dc2ea..739907c 100644
--- a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java
+++ b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilter.java
@@ -1,5 +1,5 @@
/*
- * Sone - ListNotificationFilters.java - Copyright © 2010â2015 David Roden
+ * Sone - ListNotificationFilter.java - Copyright © 2010â2020 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
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -35,8 +36,6 @@ import com.google.common.base.Optional;
/**
* Filter for {@link ListNotification}s.
- *
- * @author David âBombeâ Roden
*/
@Singleton
public class ListNotificationFilter {
@@ -66,7 +65,7 @@ public class ListNotificationFilter {
*/
@SuppressWarnings("unchecked")
public List filterNotifications(Collection extends Notification> notifications, Sone currentSone) {
- List filteredNotifications = new ArrayList();
+ List filteredNotifications = new ArrayList<>();
for (Notification notification : notifications) {
if (notification.getId().equals("new-sone-notification")) {
if ((currentSone != null) && !currentSone.getOptions().isShowNewSoneNotifications()) {
@@ -80,7 +79,7 @@ public class ListNotificationFilter {
if (!currentSone.getOptions().isShowNewPostNotifications()) {
continue;
}
- Optional> filteredNotification = filterNewPostNotification((ListNotification) notification, currentSone);
+ Optional> filteredNotification = filterPostNotification((ListNotification) notification, currentSone);
if (filteredNotification.isPresent()) {
filteredNotifications.add(filteredNotification.get());
}
@@ -97,7 +96,7 @@ public class ListNotificationFilter {
filteredNotifications.add(filteredNotification.get());
}
} else if (notification.getId().equals("mention-notification")) {
- Optional> filteredNotification = filterNewPostNotification((ListNotification) notification, null);
+ Optional> filteredNotification = filterPostNotification((ListNotification) notification, null);
if (filteredNotification.isPresent()) {
filteredNotifications.add(filteredNotification.get());
}
@@ -109,32 +108,27 @@ public class ListNotificationFilter {
}
/**
- * 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> filterNewPostNotification(@Nonnull ListNotification newPostNotification,
- @Nonnull Sone currentSone) {
- List newPosts = from(newPostNotification.getElements()).filter(postVisibilityFilter.isVisible(currentSone)).toList();
+ private Optional> filterPostNotification(@Nonnull ListNotification postNotification,
+ @Nullable Sone currentSone) {
+ List 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 filteredNotification = new ListNotification(newPostNotification);
+ ListNotification filteredNotification = new ListNotification<>(postNotification);
filteredNotification.setElements(newPosts);
- filteredNotification.setLastUpdateTime(newPostNotification.getLastUpdatedTime());
+ filteredNotification.setLastUpdateTime(postNotification.getLastUpdatedTime());
return Optional.of(filteredNotification);
}
@@ -161,7 +155,7 @@ public class ListNotificationFilter {
if (newReplies.size() == newReplyNotification.getElements().size()) {
return Optional.of(newReplyNotification);
}
- ListNotification filteredNotification = new ListNotification(newReplyNotification);
+ ListNotification filteredNotification = new ListNotification<>(newReplyNotification);
filteredNotification.setElements(newReplies);
filteredNotification.setLastUpdateTime(newReplyNotification.getLastUpdatedTime());
return Optional.of(filteredNotification);