From: David ‘Bombe’ Roden Date: Sun, 22 Jan 2023 09:31:45 +0000 (+0100) Subject: 🚧 Filter new replies using the current Sone X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=454ad5f433803239d36b21a8fe7ad9570a61cbf6;p=Sone.git 🚧 Filter new replies using the current Sone --- 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()