This fixes #122.
import java.util.Comparator;
import java.util.UUID;
+import net.pterodactylus.util.filter.Filter;
+
/**
* A post is a short message that a user writes in his Sone to let other users
* know what is going on.
};
+ /** Filter for posts with timestamps from the future. */
+ public static final Filter<Post> FUTURE_POSTS_FILTER = new Filter<Post>() {
+
+ @Override
+ public boolean filterObject(Post post) {
+ return post.getTime() <= System.currentTimeMillis();
+ }
+
+ };
+
/** The GUID of the post. */
private final UUID id;
import java.util.Comparator;
import java.util.UUID;
+import net.pterodactylus.util.filter.Filter;
+
/**
* A reply is like a {@link Post} but can never be posted on its own, it always
* refers to another {@link Post}.
};
+ /** Filter for replies with timestamps from the future. */
+ public static final Filter<Reply> FUTURE_REPLIES_FILTER = new Filter<Reply>() {
+
+ @Override
+ public boolean filterObject(Reply reply) {
+ return reply.getTime() <= System.currentTimeMillis();
+ }
+
+ };
+
/** The ID of the reply. */
private final UUID id;
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.util.filter.Filters;
import net.pterodactylus.util.template.ReflectionAccessor;
import net.pterodactylus.util.template.TemplateContext;
public Object get(TemplateContext templateContext, Object object, String member) {
Post post = (Post) object;
if ("replies".equals(member)) {
- return core.getReplies(post);
+ return Filters.filteredList(core.getReplies(post), Reply.FUTURE_REPLIES_FILTER);
} else if (member.equals("likes")) {
return core.getLikes(post);
} else if (member.equals("liked")) {
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.collection.Pagination;
+import net.pterodactylus.util.filter.Filters;
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
}
}
}
+ allPosts = Filters.filteredList(allPosts, Post.FUTURE_POSTS_FILTER);
Collections.sort(allPosts, Post.TIME_COMPARATOR);
Pagination<Post> pagination = new Pagination<Post>(allPosts, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
templateContext.set("pagination", pagination);
posts.addAll(sone.getPosts());
}
@SuppressWarnings("synthetic-access")
- Set<Hit<Post>> postHits = getHits(posts, phrases, new PostStringGenerator());
+ Set<Hit<Post>> postHits = getHits(Filters.filteredSet(posts, Post.FUTURE_POSTS_FILTER), phrases, new PostStringGenerator());
/* now filter. */
soneHits = Filters.filteredSet(soneHits, Hit.POSITIVE_FILTER);
if (post.getRecipient() != null) {
postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(post.getRecipient()));
}
- for (Reply reply : webInterface.getCore().getReplies(post)) {
+ for (Reply reply : Filters.filteredList(webInterface.getCore().getReplies(post), Reply.FUTURE_REPLIES_FILTER)) {
postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(reply.getSone()));
postString.append(' ').append(reply.getText());
}