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=cf84ebf5601fd189fbd17fb7384c771b5675a838;hpb=d3341150dde11b1d510193b71b22db85e426d6fb;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 cf84ebf..308074a 100644 --- a/src/main/java/net/pterodactylus/sone/notify/PostVisibilityFilter.java +++ b/src/main/java/net/pterodactylus/sone/notify/PostVisibilityFilter.java @@ -1,90 +1,20 @@ package net.pterodactylus.sone.notify; import java.util.function.Predicate; - -import static com.google.common.base.Preconditions.checkNotNull; - 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; -/** - * Filters {@link Notification}s involving {@link Post}s. - */ -@Singleton -public class PostVisibilityFilter { +import com.google.inject.ImplementedBy; + +@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: - * - *

- * If {@code post} is not {@code null} more checks are performed, and the - * post will be invisible if: - *

- * - * 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 post -> (post != null) && isPostVisible(currentSone, post); - } + Predicate isVisible(@Nullable Sone currentSone); }