From: David ‘Bombe’ Roden Date: Sat, 26 Oct 2013 01:06:03 +0000 (+0200) Subject: Filter future replies when encoding single posts. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=959c51e271d7da6566ecd13b912ede0d5e627b3d;p=Sone.git Filter future replies when encoding single posts. --- diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 1e7a3ed..a66fdae 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -273,7 +273,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand { protected SimpleFieldSet encodePostWithReplies(Post post, String prefix) { SimpleFieldSetBuilder postBuilder = createPostBuilderFromPost(post, prefix); - List replies = post.getReplies(); + List replies = from(post.getReplies()).filter(FUTURE_REPLY_FILTER).toList(); postBuilder.put(encodeReplies(replies, prefix)); return postBuilder.get(); diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index c50d9ca..3ac7328 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -230,11 +230,17 @@ public class AbstractSoneCommandTest { PostReply postReply = mock(PostReply.class); when(postReply.getId()).thenReturn(randomUUID().toString()); when(postReply.getSone()).thenReturn(sone); - when(postReply.getTime()).thenReturn((long) (Math.random() * Long.MAX_VALUE)); + when(postReply.getTime()).thenReturn(System.currentTimeMillis()); when(postReply.getText()).thenReturn(text); return postReply; } + private PostReply createFuturePostReply(Sone sone, String text) { + PostReply postReply = createPostReply(sone, text); + when(postReply.getTime()).thenReturn(System.currentTimeMillis() + 86400000); + return postReply; + } + @Test public void testEncodingLikes() throws FSParseException { List likes = prepareMultipleSones(); @@ -436,6 +442,26 @@ public class AbstractSoneCommandTest { } @Test + public void testEncodingAPostWithoutRecipientWithFutureReplies() throws FSParseException { + Sone sone = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test", "First", "M.", "Last", (long) (Math.random() * Long.MAX_VALUE)); + Post post = createPost(sone, null, (long) (Math.random() * Long.MAX_VALUE), "Some Text."); + PostReply postReply = createFuturePostReply(sone, "Reply."); + when(post.getReplies()).thenReturn(asList(postReply)); + SimpleFieldSet postFieldSet = abstractSoneCommand.encodePostWithReplies(post, "Post."); + assertThat(postFieldSet, notNullValue()); + assertThat(postFieldSet.get("Post.ID"), is(post.getId())); + assertThat(postFieldSet.get("Post.Sone"), is(sone.getId())); + assertThat(postFieldSet.get("Post.Recipient"), nullValue()); + assertThat(postFieldSet.getLong("Post.Time"), is(post.getTime())); + assertThat(postFieldSet.get("Post.Text"), is(post.getText())); + assertThat(postFieldSet.getInt("Post.Replies.Count"), is(0)); + assertThat(postFieldSet.get("Post.Replies.0.ID"), nullValue()); + assertThat(postFieldSet.get("Post.Replies.0.Sone"), nullValue()); + assertThat(postFieldSet.get("Post.Replies.0.Time"), nullValue()); + assertThat(postFieldSet.get("Post.Replies.0.Text"), nullValue()); + } + + @Test public void testEncodingAPostWithRecipientAndReplies() throws FSParseException { Sone sone = createSone("jXH8d-eFdm14R69WyaCgQoSjaY0jl-Ut6etlXjK0e6E", "Test", "First", "M.", "Last", (long) (Math.random() * Long.MAX_VALUE)); Post post = createPost(sone, "KpoohJSbZGltHHG-YsxKV8ojjS5gwScRv50kl3AkLXg", (long) (Math.random() * Long.MAX_VALUE), "Some Text.");