import net.pterodactylus.sone.data.Post
import net.pterodactylus.sone.data.PostReply
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.notify.ListNotification
import net.pterodactylus.sone.notify.PostVisibilityFilter
import net.pterodactylus.sone.notify.ReplyVisibilityFilter
private val replyVisibilityFilter: ReplyVisibilityFilter
) {
- fun newPosts(): Collection<Post> =
+ fun newPosts(currentSone: Sone? = null): Collection<Post> =
listOf(newPostNotification, localPostNotification)
.flatMap(ListNotification<Post>::elements)
- .filter { postVisibilityFilter.isPostVisible(null, it) }
+ .filter { postVisibilityFilter.isPostVisible(currentSone, it) }
fun newReplies(): Collection<PostReply> =
listOf(newReplyNotification, localReplyNotification)
import com.google.inject.name.Names.named
import net.pterodactylus.sone.data.Post
import net.pterodactylus.sone.data.PostReply
+import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.notify.ListNotification
+import net.pterodactylus.sone.notify.PostVisibilityFilter
import net.pterodactylus.sone.notify.matchThisPost
import net.pterodactylus.sone.notify.matchThisReply
import net.pterodactylus.sone.notify.showAllPosts
import net.pterodactylus.sone.notify.showAllReplies
+import net.pterodactylus.sone.test.createLocalSone
import net.pterodactylus.sone.test.createPost
import net.pterodactylus.sone.test.createPostReply
import net.pterodactylus.sone.test.getInstance
assertThat(newElements.newReplies(), containsInAnyOrder(reply2))
}
+ @Test
+ fun `new posts are filtered using the given Sone`() {
+ val postVisibilityFilter = object : PostVisibilityFilter {
+ override fun isPostVisible(sone: Sone?, post: Post) = (sone == localSone) && (post == post2)
+ }
+ val newElements = NewElements(newPostNotification, newReplyNotification, localPostNotification, localReplyNotification, postVisibilityFilter, showAllReplies)
+ assertThat(newElements.newPosts(localSone), contains(post2))
+ }
+
}
private val post1 = createPost()
private val post2 = createPost()
private val reply1 = createPostReply()
private val reply2 = createPostReply()
+private val localSone = createLocalSone()