private val replyVisibilityFilter: ReplyVisibilityFilter
) {
- val newPosts: Collection<Post>
- get() = listOf(newPostNotification, localPostNotification)
- .flatMap(ListNotification<Post>::elements)
- .filter { postVisibilityFilter.isPostVisible(null, it) }
+ fun newPosts(): Collection<Post> =
+ listOf(newPostNotification, localPostNotification)
+ .flatMap(ListNotification<Post>::elements)
+ .filter { postVisibilityFilter.isPostVisible(null, it) }
+
+ fun newReplies(): Collection<PostReply> =
+ listOf(newReplyNotification, localReplyNotification)
+ .flatMap(ListNotification<PostReply>::elements)
+ .filter { replyVisibilityFilter.isReplyVisible(null, it) }
- val newReplies: Collection<PostReply>
- get() = listOf(newReplyNotification, localReplyNotification)
- .flatMap(ListNotification<PostReply>::elements)
- .filter { replyVisibilityFilter.isReplyVisible(null, it) }
}
this["options"] = currentSone?.options?.toJsonOptions() ?: jsonObject {}
this["notificationHash"] = webInterface.getNotifications(currentSone).sortedBy { it.createdTime }.hashCode()
this["sones"] = request.httpRequest.getParam("soneIds").split(',').mapNotNull(core::getSone).plus(currentSone).filterNotNull().toJsonSones()
- this["newPosts"] = newElements.newPosts.toJsonPosts()
- this["newReplies"] = newElements.newReplies.toJsonReplies()
+ this["newPosts"] = newElements.newPosts().toJsonPosts()
+ this["newReplies"] = newElements.newReplies().toJsonReplies()
this["linkedElements"] = request.httpRequest.getParam("elements", "[]").asJson().map(JsonNode::asText).map(elementLoader::loadElement).toJsonElements()
}
}
override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) =
getCurrentSone(soneRequest.toadletContext).let { currentSone ->
- (newElements.newPosts + newElements.newReplies.mapPresent { it.post })
+ (newElements.newPosts() + newElements.newReplies().mapPresent { it.post })
.distinct()
.sortedByDescending { it.time }
.let { posts ->
@Test
fun `new posts include new and local posts`() {
- assertThat(newElements.newPosts, containsInAnyOrder(post1, post2))
+ assertThat(newElements.newPosts(), containsInAnyOrder(post1, post2))
}
@Test
fun `new posts are filtered`() {
val newElements = NewElements(newPostNotification, newReplyNotification, localPostNotification, localReplyNotification, matchThisPost(post2), showAllReplies)
- assertThat(newElements.newPosts, contains(post2))
+ assertThat(newElements.newPosts(), contains(post2))
}
@Test
fun `new replies include new and local replies`() {
- assertThat(newElements.newReplies, containsInAnyOrder(reply1, reply2))
+ assertThat(newElements.newReplies(), containsInAnyOrder(reply1, reply2))
}
@Test
fun `new replies are filtered`() {
val newElements = NewElements(newPostNotification, newReplyNotification, localPostNotification, localReplyNotification, showAllPosts, matchThisReply(reply2))
- assertThat(newElements.newReplies, containsInAnyOrder(reply2))
+ assertThat(newElements.newReplies(), containsInAnyOrder(reply2))
}
}
linkedElements[it.getArgument(0)] ?: LinkedElement(it.getArgument(0), loading = true)
}
- whenever(newElements.newPosts).then { newPosts.values }
- whenever(newElements.newReplies).then { newReplies.values }
+ whenever(newElements.newPosts()).then { newPosts.values }
+ whenever(newElements.newReplies()).then { newReplies.values }
whenever(currentSone.options).thenReturn(DefaultSoneOptions())
currentSone.mock("soneId", "Sone_Id", true, 1000, idle)
val postReplies = asList(mock<PostReply>(), mock())
whenever(postReplies[0].post).thenReturn(posts[0].asOptional())
whenever(postReplies[1].post).thenReturn(extraPost.asOptional())
- whenever(newElements.newPosts).thenReturn(posts)
- whenever(newElements.newReplies).thenReturn(postReplies)
+ whenever(newElements.newPosts()).thenReturn(posts)
+ whenever(newElements.newReplies()).thenReturn(postReplies)
verifyNoRedirect {
val renderedPosts = templateContext.get<List<Post>>("posts", List::class.java)
fun `posts are paginated properly`() {
webInterface.core.preferences.newPostsPerPage = 2
val posts = listOf(mock<Post>().withTime(2000), mock<Post>().withTime(3000), mock<Post>().withTime(1000))
- whenever(newElements.newPosts).thenReturn(posts)
+ whenever(newElements.newPosts()).thenReturn(posts)
verifyNoRedirect {
assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(posts[1], posts[0]))
}
webInterface.core.preferences.newPostsPerPage = 2
addHttpRequestParameter("page", "1")
val posts = listOf(mock<Post>().withTime(2000), mock<Post>().withTime(3000), mock<Post>().withTime(1000))
- whenever(newElements.newPosts).thenReturn(posts)
+ whenever(newElements.newPosts()).thenReturn(posts)
verifyNoRedirect {
assertThat((templateContext["pagination"] as Pagination<Post>).items, contains(posts[2]))
}