From 871af6a15ec10c5df170955f5d65285a3f6982fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 27 Apr 2011 21:46:54 +0200 Subject: [PATCH] =?utf8?q?Add=20method=20to=20check=20a=20post=E2=80=99s?= =?utf8?q?=20visibility.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/notify/ListNotificationFilters.java | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java index f2bff09..7491e70 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java @@ -24,7 +24,10 @@ import java.util.List; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.freenet.wot.OwnIdentity; +import net.pterodactylus.sone.freenet.wot.Trust; import net.pterodactylus.util.notify.Notification; +import net.pterodactylus.util.validation.Validation; /** * Filter for {@link ListNotification}s. @@ -166,4 +169,50 @@ public class ListNotificationFilters { return null; } + /** + * Checks whether a post is visible to the given Sone. A post is not + * considered visible if one of the following statements is true: + * + * If none of these statements is true the post is considered visible. + * + * @param sone + * The Sone that checks for a post’s visibility + * @param post + * The post to check for visibility + * @return {@code true} if the post is considered visible, {@code false} + * otherwise + */ + public static boolean isPostVisible(Sone sone, Post post) { + Validation.begin().isNotNull("Sone", sone).isNotNull("Post", post).check().isNotNull("Sone’s Identity", sone.getIdentity()).check().isInstanceOf("Sone’s Identity", sone.getIdentity(), OwnIdentity.class).check(); + Sone postSone = post.getSone(); + if (postSone == null) { + return false; + } + Trust trust = postSone.getIdentity().getTrust((OwnIdentity) sone.getIdentity()); + if (trust != null) { + if ((trust.getExplicit() != null) && (trust.getExplicit() < 0)) { + return false; + } + if ((trust.getExplicit() == null) && (trust.getImplicit() != null) && (trust.getImplicit() < 0)) { + return false; + } + } else { + return false; + } + if ((!postSone.equals(sone)) && !sone.hasFriend(postSone.getId()) && !sone.equals(post.getRecipient())) { + return false; + } + return true; + } + } -- 2.7.4