From 5aaa1e1dc761fa0c8b6745b7b022c0a19d248c68 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 8 Feb 2020 13:27:45 +0100 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Move=20removal=20of=20remot?= =?utf8?q?e=20posts=20to=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/web/WebInterface.java | 18 ------------------ .../sone/web/notification/NewRemotePostHandler.kt | 10 ++++++++++ .../sone/web/notification/NewRemotePostHandlerTest.kt | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 18 deletions(-) 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") -- 2.7.4