🚧 Filter new replies using the current Sone
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 22 Jan 2023 09:31:45 +0000 (10:31 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 22 Jan 2023 09:31:45 +0000 (10:31 +0100)
src/main/kotlin/net/pterodactylus/sone/web/NewElements.kt
src/test/kotlin/net/pterodactylus/sone/web/NewElementsTest.kt

index c45d15e..4dd78cb 100644 (file)
@@ -44,9 +44,9 @@ class NewElements @Inject constructor(
                        .flatMap(ListNotification<Post>::elements)
                        .filter { postVisibilityFilter.isPostVisible(currentSone, it) }
 
-       fun newReplies(): Collection<PostReply> =
+       fun newReplies(currentSone: Sone? = null): Collection<PostReply> =
                listOf(newReplyNotification, localReplyNotification)
                        .flatMap(ListNotification<PostReply>::elements)
-                       .filter { replyVisibilityFilter.isReplyVisible(null, it) }
+                       .filter { replyVisibilityFilter.isReplyVisible(currentSone, it) }
 
 }
index 2b4436d..fbd40bc 100644 (file)
@@ -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()