X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FListNotificationFilters.java;h=717551923f72044c0f0e2fea5494164ea66a0c03;hb=7767adb4bf17f4170989f95af5eb3dde42a2fc00;hp=908ea2be50f054644d077c5d5d612583978eeb13;hpb=a2c1ff645a1c1369f75e145932637721538d3794;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java index 908ea2b..7175519 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.List; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.wot.OwnIdentity; @@ -54,13 +55,20 @@ public class ListNotificationFilters { public static List filterNotifications(Collection notifications, Sone currentSone) { List filteredNotifications = new ArrayList(); for (Notification notification : notifications) { - if (notification.getId().equals("new-post-notification") || notification.getId().equals("mention-notification")) { - ListNotification filteredNotification = filterNewPostNotification((ListNotification) notification, currentSone); + if (notification.getId().equals("new-sone-notification") && ((currentSone == null) || (currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get()))) { + filteredNotifications.add(notification); + } else if (notification.getId().equals("new-post-notification") && ((currentSone == null) || (currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get()))) { + ListNotification filteredNotification = filterNewPostNotification((ListNotification) notification, currentSone, true); + if (filteredNotification != null) { + filteredNotifications.add(filteredNotification); + } + } else if (notification.getId().equals("new-reply-notification") && ((currentSone == null) || (currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get()))) { + ListNotification filteredNotification = filterNewReplyNotification((ListNotification) notification, currentSone); if (filteredNotification != null) { filteredNotifications.add(filteredNotification); } - } else if (notification.getId().equals("new-reply-notification")) { - ListNotification filteredNotification = filterNewReplyNotification((ListNotification) notification, currentSone); + } else if (notification.getId().equals("mention-notification")) { + ListNotification filteredNotification = filterNewPostNotification((ListNotification) notification, null, false); if (filteredNotification != null) { filteredNotifications.add(filteredNotification); } @@ -73,19 +81,23 @@ public class ListNotificationFilters { /** * 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. + * 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. * * @param newPostNotification * The new-post notification * @param currentSone * The current Sone, or {@code null} if not logged in + * @param soneRequired + * Whether a non-{@code null} Sone in {@code currentSone} is + * required * @return The filtered new-post notification, or {@code null} if the * notification should be removed */ - public static ListNotification filterNewPostNotification(ListNotification newPostNotification, Sone currentSone) { - if (currentSone == null) { + public static ListNotification filterNewPostNotification(ListNotification newPostNotification, Sone currentSone, boolean soneRequired) { + if (soneRequired && (currentSone == null)) { return null; } List newPosts = new ArrayList(); @@ -120,12 +132,12 @@ public class ListNotificationFilters { * @return The filtered new-reply notification, or {@code null} if the * notification should be removed */ - public static ListNotification filterNewReplyNotification(ListNotification newReplyNotification, Sone currentSone) { + public static ListNotification filterNewReplyNotification(ListNotification newReplyNotification, Sone currentSone) { if (currentSone == null) { return null; } - List newReplies = new ArrayList(); - for (Reply reply : newReplyNotification.getElements()) { + List newReplies = new ArrayList(); + for (PostReply reply : newReplyNotification.getElements()) { if (isReplyVisible(currentSone, reply)) { newReplies.add(reply); } @@ -136,7 +148,7 @@ public class ListNotificationFilters { if (newReplies.size() == newReplyNotification.getElements().size()) { return newReplyNotification; } - ListNotification filteredNotification = new ListNotification(newReplyNotification); + ListNotification filteredNotification = new ListNotification(newReplyNotification); filteredNotification.setElements(newReplies); filteredNotification.setLastUpdateTime(newReplyNotification.getLastUpdatedTime()); return filteredNotification; @@ -228,7 +240,7 @@ public class ListNotificationFilters { * @return {@code true} if the reply is considered visible, {@code false} * otherwise */ - public static boolean isReplyVisible(Sone sone, Reply reply) { + public static boolean isReplyVisible(Sone sone, PostReply reply) { Validation.begin().isNotNull("Reply", reply).check(); Post post = reply.getPost(); if (post == null) {