From 91b5acd80fbb818e8b51c20c43660401aad35d3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 6 May 2011 15:27:37 +0200 Subject: [PATCH] Add method to check the visibility of a reply. --- .../sone/notify/ListNotificationFilters.java | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java index 58afc17..bc27173 100644 --- a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java +++ b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java @@ -213,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: + * + * 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; } -- 2.7.4