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