X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FListNotificationFilters.java;h=7491e70aef7b3e0a33257253814fc323b82839a2;hb=871af6a15ec10c5df170955f5d65285a3f6982fb;hp=f2bff09069db232ed3c14192bba77b1db936ae1b;hpb=b1c2516dedba75c15e4b62d9c1630f1c85fa085c;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 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:
+ *
+ * - The post does not have a Sone.
+ * - The Sone of the post is not the given Sone, the given Sone does not
+ * follow the postâs Sone, and the given Sone is not the recipient of the
+ * post.
+ * - The trust relationship between the two Sones can not be retrieved.
+ * - The given Sone has explicitely assigned negative trust to the postâs
+ * Sone.
+ * - The given Sone has not explicitely assigned negative trust to the
+ * postâs Sone but the implicit trust is negative.
+ *
+ * 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;
+ }
+
}