From 454ad5f433803239d36b21a8fe7ad9570a61cbf6 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:31:45 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Filter=20new=20replies=20using=20?= =?utf8?q?the=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 | 4 ++-- src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt | 10 ++++++++++ 2 files changed, 12 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 c45d15e..4dd78cb 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/NewElements.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/NewElements.kt @@ -44,9 +44,9 @@ class NewElements @Inject constructor( .flatMap(ListNotification::elements) .filter { postVisibilityFilter.isPostVisible(currentSone, it) } - fun newReplies(): Collection = + fun newReplies(currentSone: Sone? = null): Collection = listOf(newReplyNotification, localReplyNotification) .flatMap(ListNotification::elements) - .filter { replyVisibilityFilter.isReplyVisible(null, it) } + .filter { replyVisibilityFilter.isReplyVisible(currentSone, it) } } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt index 2b4436d..fbd40bc 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt @@ -23,6 +23,7 @@ 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 import net.pterodactylus.sone.notify.matchThisPost import net.pterodactylus.sone.notify.matchThisReply import net.pterodactylus.sone.notify.showAllPosts @@ -96,6 +97,15 @@ class NewElementsTest { assertThat(newElements.newPosts(localSone), contains(post2)) } + @Test + fun `new replies are filtered using the given Sone`() { + val replyVisibilityFilter = object : ReplyVisibilityFilter { + override fun isReplyVisible(sone: Sone?, reply: PostReply) = (sone == localSone) && (reply == reply2) + } + val newElements = NewElements(newPostNotification, newReplyNotification, localPostNotification, localReplyNotification, showAllPosts, replyVisibilityFilter) + assertThat(newElements.newReplies(localSone), contains(reply2)) + } + } private val post1 = createPost() -- 2.7.4