Add parameter to include replies in encodePosts().
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Apr 2011 14:08:01 +0000 (16:08 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 8 Apr 2011 14:08:01 +0000 (16:08 +0200)
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java

index 7cc4b0f..4ad6389 100644 (file)
@@ -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<? extends Post> posts) {
+       public SimpleFieldSet encodePosts(Collection<? extends Post> 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();
index 38b240a..f1ff9a8 100644 (file)
@@ -73,10 +73,10 @@ public class GetPostFeedCommand extends AbstractSoneCommand {
                Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
 
                if (sortedPosts.size() < startPost) {
-                       return new Response(encodePosts(Collections.<Post> emptyList()));
+                       return new Response(encodePosts(Collections.<Post> 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));
        }
 
 }