♻️ Move removal of remote posts to handler
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 8 Feb 2020 12:27:45 +0000 (13:27 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 8 Feb 2020 12:27:45 +0000 (13:27 +0100)
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandler.kt
src/test/kotlin/net/pterodactylus/sone/web/notification/NewRemotePostHandlerTest.kt

index 027fb7f..1e6e6fb 100644 (file)
@@ -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.
         *
index 0c2368a..6efff85 100644 (file)
@@ -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)
+       }
+
 }
index fc04b8b..805731d 100644 (file)
@@ -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")