From 2278f98a3c8f0c5ed0e5c249435ba8c394f80768 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 8 Apr 2011 16:08:01 +0200 Subject: [PATCH] Add parameter to include replies in encodePosts(). --- .../java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java | 9 ++++++++- src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 7cc4b0f..4ad6389 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -28,6 +28,7 @@ import net.pterodactylus.sone.freenet.fcp.AbstractCommand; import net.pterodactylus.sone.freenet.fcp.Command; import net.pterodactylus.sone.freenet.fcp.FcpException; import net.pterodactylus.sone.template.SoneAccessor; +import net.pterodactylus.util.filter.Filters; import freenet.node.FSParseException; import freenet.support.SimpleFieldSet; @@ -123,9 +124,12 @@ public abstract class AbstractSoneCommand extends AbstractCommand { * * @param posts * The posts to encode + * @param includeReplies + * {@code true} to include the replies, {@code false} to not + * include the replies * @return The simple field set containing the posts */ - public SimpleFieldSet encodePosts(Collection posts) { + public SimpleFieldSet encodePosts(Collection posts, boolean includeReplies) { SimpleFieldSetBuilder postBuilder = new SimpleFieldSetBuilder(); int postIndex = 0; @@ -139,6 +143,9 @@ public abstract class AbstractSoneCommand extends AbstractCommand { } postBuilder.put(postPrefix + ".Time", post.getTime()); postBuilder.put(postPrefix + ".Text", post.getText()); + if (includeReplies) { + postBuilder.put(encodeReplies(Filters.filteredList(core.getReplies(post), Reply.FUTURE_REPLIES_FILTER), postPrefix + ".")); + } } return postBuilder.get(); diff --git a/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java b/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java index 38b240a..f1ff9a8 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java @@ -73,10 +73,10 @@ public class GetPostFeedCommand extends AbstractSoneCommand { Collections.sort(sortedPosts, Post.TIME_COMPARATOR); if (sortedPosts.size() < startPost) { - return new Response(encodePosts(Collections. emptyList())); + return new Response(encodePosts(Collections. emptyList(), false)); } - return new Response(encodePosts(sortedPosts.subList(startPost, (maxPosts == -1) ? sortedPosts.size() : Math.min(startPost + maxPosts, sortedPosts.size())))); + return new Response(encodePosts(sortedPosts.subList(startPost, (maxPosts == -1) ? sortedPosts.size() : Math.min(startPost + maxPosts, sortedPosts.size())), true)); } } -- 2.7.4