1 package net.pterodactylus.sone.notify;
3 import javax.annotation.Nonnull;
4 import javax.annotation.Nullable;
5 import javax.inject.Singleton;
7 import net.pterodactylus.sone.data.Post;
8 import net.pterodactylus.sone.data.Sone;
9 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
10 import net.pterodactylus.sone.freenet.wot.Trust;
11 import net.pterodactylus.util.notify.Notification;
14 * Filters {@link Notification}s involving {@link Post}s.
17 public class DefaultPostVisibilityFilter implements PostVisibilityFilter {
20 * Checks whether a post is visible to the given Sone. A post is not
21 * considered visible if one of the following statements is true:
23 * <li>The post does not have a Sone.</li>
24 * <li>The post’s {@link Post#getTime() time} is in the future.</li>
27 * If {@code post} is not {@code null} more checks are performed, and the
28 * post will be invisible if:
31 * <li>The Sone of the post is not the given Sone, the given Sone does not
32 * follow the post’s Sone, and the given Sone is not the recipient of the
34 * <li>The trust relationship between the two Sones can not be retrieved.</li>
35 * <li>The given Sone has explicitely assigned negative trust to the post’s
37 * <li>The given Sone has not explicitely assigned negative trust to the
38 * post’s Sone but the implicit trust is negative.</li>
40 * If none of these statements is true the post is considered visible.
43 * The Sone that checks for a post’s visibility (may be
44 * {@code null} to skip Sone-specific checks, such as trust)
46 * The post to check for visibility
47 * @return {@code true} if the post is considered visible, {@code false}
51 public boolean isPostVisible(@Nullable Sone sone, @Nonnull Post post) {
52 if (!post.isLoaded()) {
55 Sone postSone = post.getSone();
57 Trust trust = postSone.getIdentity().getTrust((OwnIdentity) sone.getIdentity());
59 if ((trust.getExplicit() != null) && (trust.getExplicit() < 0)) {
62 if ((trust.getExplicit() == null) && (trust.getImplicit() != null) && (trust.getImplicit() < 0)) {
67 * a null trust means that the trust updater has not yet
68 * received a trust value for this relation. if we return false,
69 * the post feed will stay empty until the trust updater has
70 * received trust values. to prevent this we simply assume that
71 * posts are visible if there is no trust.
74 if ((!postSone.equals(sone)) && !sone.hasFriend(postSone.getId()) && !sone.getId().equals(post.getRecipientId().orNull())) {
78 return post.getTime() <= System.currentTimeMillis();