X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FListNotificationFilters.java;h=264e77c3ddfed5c9e56256a61ec030f6ee9adca1;hb=2a700a6d84a4e2705f33870c0b9d7a0b78bf37f4;hp=7491e70aef7b3e0a33257253814fc323b82839a2;hpb=871af6a15ec10c5df170955f5d65285a3f6982fb;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 7491e70..264e77c 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java @@ -93,7 +93,7 @@ public class ListNotificationFilters { } List newPosts = new ArrayList(); for (Post post : newPostNotification.getElements()) { - if ((post.getSone() != null) && (currentSone.hasFriend(post.getSone().getId()) || currentSone.equals(post.getSone()) || currentSone.equals(post.getRecipient()))) { + if (isPostVisible(currentSone, post)) { newPosts.add(post); } } @@ -128,7 +128,7 @@ public class ListNotificationFilters { } List newReplies = new ArrayList(); for (Reply reply : newReplyNotification.getElements()) { - if (((reply.getPost().getSone() != null) && currentSone.hasFriend(reply.getPost().getSone().getId())) || currentSone.equals(reply.getPost().getSone()) || currentSone.equals(reply.getPost().getRecipient())) { + if (isReplyVisible(currentSone, reply)) { newReplies.add(reply); } } @@ -182,6 +182,7 @@ public class ListNotificationFilters { * Sone. *
  • The given Sone has not explicitely assigned negative trust to the * post’s Sone but the implicit trust is negative.
  • + *
  • The post’s {@link Post#getTime() time} is in the future.
  • * * If none of these statements is true the post is considered visible. * @@ -212,6 +213,50 @@ public class ListNotificationFilters { if ((!postSone.equals(sone)) && !sone.hasFriend(postSone.getId()) && !sone.equals(post.getRecipient())) { return false; } + if (post.getTime() > System.currentTimeMillis()) { + return false; + } + return true; + } + + /** + * Checks whether a reply is visible to the given Sone. A reply is not + * considered visible if one of the following statements is true: + *
      + *
    • The reply does not have a post.
    • + *
    • The reply’s post does not have a Sone.
    • + *
    • The Sone of the reply’s post is not the given Sone, the given Sone + * does not follow the reply’s post’s Sone, and the given Sone is not the + * recipient of the reply’s 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 + * reply’s post’s Sone but the implicit trust is negative.
    • + *
    • The reply’s post’s {@link Post#getTime() time} is in the future.
    • + *
    • The reply’s {@link Reply#getTime() time} is in the future.
    • + *
    + * If none of these statements is true the reply is considered visible. + * + * @param sone + * The Sone that checks for a post’s visibility + * @param reply + * The reply to check for visibility + * @return {@code true} if the reply is considered visible, {@code false} + * otherwise + */ + public static boolean isReplyVisible(Sone sone, Reply reply) { + Validation.begin().isNotNull("Sone", sone).isNotNull("Reply", reply).check().isNotNull("Sone’s Identity", sone.getIdentity()).check().isInstanceOf("Sone’s Identity", sone.getIdentity(), OwnIdentity.class).check(); + Post post = reply.getPost(); + if (post == null) { + return false; + } + if (!isPostVisible(sone, post)) { + return false; + } + if (reply.getTime() > System.currentTimeMillis()) { + return false; + } return true; }