1 package net.pterodactylus.sone.notify;
3 import java.util.function.Predicate;
5 import static com.google.common.base.Preconditions.checkNotNull;
7 import javax.annotation.Nonnull;
8 import javax.annotation.Nullable;
9 import javax.inject.Inject;
10 import javax.inject.Singleton;
12 import net.pterodactylus.sone.data.Post;
13 import net.pterodactylus.sone.data.PostReply;
14 import net.pterodactylus.sone.data.Sone;
16 import com.google.common.base.Optional;
19 * Filter that checks a {@link PostReply} for visibility.
22 public class DefaultReplyVisibilityFilter implements ReplyVisibilityFilter {
24 private final PostVisibilityFilter postVisibilityFilter;
27 public DefaultReplyVisibilityFilter(@Nonnull PostVisibilityFilter postVisibilityFilter) {
28 this.postVisibilityFilter = postVisibilityFilter;
32 * Checks whether a reply is visible to the given Sone. A reply is not
33 * considered visible if one of the following statements is true:
35 * <li>The reply does not have a post.</li>
36 * <li>The reply’s post {@link PostVisibilityFilter#isPostVisible(Sone, Post) is not visible}.</li>
37 * <li>The reply’s {@link PostReply#getTime() time} is in the future.</li>
39 * If none of these statements is true the reply is considered visible.
42 * The Sone that checks for a post’s visibility (may be
43 * {@code null} to skip Sone-specific checks, such as trust)
45 * The reply to check for visibility
46 * @return {@code true} if the reply is considered visible, {@code false}
50 public boolean isReplyVisible(@Nullable Sone sone, @Nonnull PostReply reply) {
51 checkNotNull(reply, "reply must not be null");
52 Optional<Post> post = reply.getPost();
53 if (!post.isPresent()) {
56 if (!postVisibilityFilter.isPostVisible(sone, post.get())) {
59 return reply.getTime() <= System.currentTimeMillis();