From 5c1acc9f42d039acb0174e3ab1266d76122675ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 22 Jan 2023 10:23:55 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Filter=20new=20posts=20using=20th?= =?utf8?q?e=20current=20Sone?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/net/pterodactylus/sone/web/NewElements.kt | 5 +++-- .../kotlin/net/pterodactylus/sone/web/NewElementsTest.kt | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/NewElements.kt b/src/main/kotlin/net/pterodactylus/sone/web/NewElements.kt index 28e410c..c45d15e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/NewElements.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/NewElements.kt @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web 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 @@ -38,10 +39,10 @@ class NewElements @Inject constructor( private val replyVisibilityFilter: ReplyVisibilityFilter ) { - fun newPosts(): Collection = + fun newPosts(currentSone: Sone? = null): Collection = listOf(newPostNotification, localPostNotification) .flatMap(ListNotification::elements) - .filter { postVisibilityFilter.isPostVisible(null, it) } + .filter { postVisibilityFilter.isPostVisible(currentSone, it) } fun newReplies(): Collection = listOf(newReplyNotification, localReplyNotification) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt index ccda1c7..2b4436d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt @@ -20,11 +20,14 @@ import com.google.inject.Guice 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 @@ -84,9 +87,19 @@ class NewElementsTest { 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() -- 2.7.4