X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FPostVisibilityFilter.java;h=308074a6a8e2e3337448dbcf141264227a5f7d58;hb=fedc22de1913a39285d0704a56f3d8b3f8361a00;hp=3582e3d2a96a17339a512c774121419a919ed2f6;hpb=c4ae226ec5052116cefc542ae2017036a7bc6332;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/notify/PostVisibilityFilter.java b/src/main/java/net/pterodactylus/sone/notify/PostVisibilityFilter.java
index 3582e3d..308074a 100644
--- a/src/main/java/net/pterodactylus/sone/notify/PostVisibilityFilter.java
+++ b/src/main/java/net/pterodactylus/sone/notify/PostVisibilityFilter.java
@@ -1,97 +1,20 @@
package net.pterodactylus.sone.notify;
-import static com.google.common.base.Preconditions.checkNotNull;
-
+import java.util.function.Predicate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import javax.inject.Singleton;
import net.pterodactylus.sone.data.Post;
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 com.google.common.base.Predicate;
+import com.google.inject.ImplementedBy;
-/**
- * Filters {@link Notification}s involving {@link Post}s.
- *
- * @author David âBombeâ Roden
- */
-@Singleton
-public class PostVisibilityFilter {
+@ImplementedBy(DefaultPostVisibilityFilter.class)
+public interface PostVisibilityFilter {
- /**
- * 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 postâs {@link Post#getTime() time} is in the future.
- *
- *
- * If {@code post} is not {@code null} more checks are performed, and the
- * post will be invisible if:
- *
- *
- * - 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 (may be
- * {@code null} to skip Sone-specific checks, such as trust)
- * @param post
- * The post to check for visibility
- * @return {@code true} if the post is considered visible, {@code false}
- * otherwise
- */
- boolean isPostVisible(@Nullable Sone sone, @Nonnull Post post) {
- checkNotNull(post, "post must not be null");
- if (!post.isLoaded()) {
- return false;
- }
- Sone postSone = post.getSone();
- if (sone != null) {
- 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 {
- /*
- * a null trust means that the trust updater has not yet
- * received a trust value for this relation. if we return false,
- * the post feed will stay empty until the trust updater has
- * received trust values. to prevent this we simply assume that
- * posts are visible if there is no trust.
- */
- }
- if ((!postSone.equals(sone)) && !sone.hasFriend(postSone.getId()) && !sone.getId().equals(post.getRecipientId().orNull())) {
- return false;
- }
- }
- return post.getTime() <= System.currentTimeMillis();
- }
+ boolean isPostVisible(@Nullable Sone sone, @Nonnull Post post);
@Nonnull
- public Predicate isVisible(@Nullable final Sone currentSone) {
- return new Predicate() {
- @Override
- public boolean apply(@Nullable Post post) {
- return (post != null) && isPostVisible(currentSone, post);
- }
- };
- }
+ Predicate isVisible(@Nullable Sone currentSone);
}