From: David ‘Bombe’ Roden Date: Sat, 8 Feb 2020 12:27:45 +0000 (+0100) Subject: ♻️ Move removal of remote posts to handler X-Git-Tag: v81^2~5^2~4 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=5aaa1e1dc761fa0c8b6745b7b022c0a19d248c68;p=Sone.git ♻️ Move removal of remote posts to handler --- diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 027fb7f..1e6e6fb 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -508,24 +508,6 @@ public class WebInterface implements SessionProvider { } } - // - // EVENT HANDLERS - // - - @Subscribe - public void markPostKnown(MarkPostKnownEvent markPostKnownEvent) { - removePost(markPostKnownEvent.getPost()); - } - - @Subscribe - public void postRemoved(PostRemovedEvent postRemovedEvent) { - removePost(postRemovedEvent.getPost()); - } - - private void removePost(Post post) { - newPostNotification.remove(post); - } - /** * Notifies the web interface that a {@link Sone} is being inserted. * diff --git a/src/main/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandler.kt b/src/main/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandler.kt index 0c2368a..6efff85 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandler.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandler.kt @@ -40,4 +40,14 @@ class NewRemotePostHandler @Inject constructor(private val notificationManager: } } + @Subscribe + fun postRemoved(event: PostRemovedEvent) { + notification.remove(event.post) + } + + @Subscribe + fun postMarkedKnown(event: MarkPostKnownEvent) { + notification.remove(event.post) + } + } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt index fc04b8b..805731d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt @@ -68,6 +68,20 @@ class NewRemotePostHandlerTest { assertThat(remotePostHandlerTest.notifications, not(hasItem(notification))) } + @Test + fun `handler removes post from notification if post is removed`() { + notification.add(remotePost) + remotePostHandlerTest.sendEvent(PostRemovedEvent(remotePost)) + assertThat(notification.elements, not(hasItem(remotePost))) + } + + @Test + fun `handler removes post from notification if post is marked as known`() { + notification.add(remotePost) + remotePostHandlerTest.sendEvent(MarkPostKnownEvent(remotePost)) + assertThat(notification.elements, not(hasItem(remotePost))) + } + } private val remoteSone: Sone = IdOnlySone("remote-sone")