.addAll(newPostNotification.getElements())
.addAll(localPostNotification.getElements())
.build();
- return allNewPosts.stream().filter(postVisibilityFilter.isVisible(currentSone)).collect(toSet());
+ return allNewPosts.stream().filter(p -> postVisibilityFilter.isPostVisible(currentSone, p)).collect(toSet());
}
@Nonnull
.addAll(newReplyNotification.getElements())
.addAll(localReplyNotification.getElements())
.build();
- return allNewReplies.stream().filter(replyVisibilityFilter.isVisible(currentSone)).collect(toSet());
+ return allNewReplies.stream().filter(r -> replyVisibilityFilter.isReplyVisible(currentSone, r)).collect(toSet());
}
//
fun isPostVisible(sone: Sone?, post: Post): Boolean
@JvmDefault
- fun isVisible(currentSone: Sone?): Predicate<Post?> =
- Predicate { p: Post? -> p != null && isPostVisible(currentSone, p) }
+ fun isVisible(currentSone: Sone?) =
+ { p: Post? -> p != null && isPostVisible(currentSone, p) }
}
fun isReplyVisible(sone: Sone?, reply: PostReply): Boolean
@JvmDefault
- fun isVisible(currentSone: Sone?): Predicate<PostReply> =
- Predicate { reply: PostReply -> isReplyVisible(currentSone, reply) }
+ fun isVisible(currentSone: Sone?) =
+ { reply: PostReply -> isReplyVisible(currentSone, reply) }
}
.flatMap { it.posts } +
soneRequest.core.getDirectedPosts(currentSone.id)
).distinct()
- .filter { postVisibilityFilter.isVisible(currentSone).test(it) }
+ .filter { postVisibilityFilter.isVisible(currentSone).invoke(it) }
.sortedByDescending { it.time }
.let { posts ->
posts.paginate(soneRequest.core.preferences.postsPerPage)
@Test
fun `predicate will correctly recognize visible post`() {
val post = createPost(sone = localSone)
- assertThat(postVisibilityFilter.isVisible(null).test(post), equalTo(true))
+ assertThat(postVisibilityFilter.isVisible(null).invoke(post), equalTo(true))
}
@Test
fun `predicate will correctly recognize not visible post`() {
val post = createPost(loaded = false)
- assertThat(postVisibilityFilter.isVisible(null).test(post), equalTo(false))
+ assertThat(postVisibilityFilter.isVisible(null).invoke(post), equalTo(false))
}
}
@Test
fun `predicate correctly recognizes visible reply`() {
val postReply = createPostReply(post = post)
- assertThat(replyVisibilityFilter.isVisible(localSone).test(postReply), equalTo(true))
+ assertThat(replyVisibilityFilter.isVisible(localSone).invoke(postReply), equalTo(true))
}
@Test
fun `predicate correctly recognizes not visible reply`() {
val postReply = createPostReply(post = post, time = System.currentTimeMillis() + 100000)
- assertThat(replyVisibilityFilter.isVisible(localSone).test(postReply), equalTo(false))
+ assertThat(replyVisibilityFilter.isVisible(localSone).invoke(postReply), equalTo(false))
}
}
@Before
fun setupPostVisibilityFilter() {
- whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn(Predicate<Post> { true })
+ whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn { true }
}
@Before
val followedPosts = listOf(createPost(2500, true), createPost(1500))
whenever(followedSone.posts).thenReturn(followedPosts)
whenever(currentSone.friends).thenReturn(listOf("followed1", "followed2"))
- whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn(Predicate<Post> { (it?.time ?: 10000) < 2500 })
+ whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn { (it?.time ?: 10000) < 2500 }
addSone("followed1", followedSone)
page.processTemplate(freenetRequest, templateContext)
@Suppress("UNCHECKED_CAST")