♻️ Move removal of remote posts to handler
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index 5bb4e3a..1e6e6fb 100644 (file)
@@ -169,7 +169,9 @@ public class WebInterface implements SessionProvider {
                        LinkedElementRenderFilter linkedElementRenderFilter,
                        PageToadletRegistry pageToadletRegistry, MetricRegistry metricRegistry, Translation translation, L10nFilter l10nFilter,
                        NotificationManager notificationManager, @Named("newRemotePost") ListNotification<Post> newPostNotification,
-                       @Named("localPost") ListNotification<Post> localPostNotification) {
+                       @Named("newRemotePostReply") ListNotification<PostReply> newReplyNotification,
+                       @Named("localPost") ListNotification<Post> localPostNotification,
+                       @Named("localReply") ListNotification<PostReply> localReplyNotification) {
                this.sonePlugin = sonePlugin;
                this.loaders = loaders;
                this.listNotificationFilter = listNotificationFilter;
@@ -187,19 +189,14 @@ public class WebInterface implements SessionProvider {
                this.translation = translation;
                this.notificationManager = notificationManager;
                this.newPostNotification = newPostNotification;
+               this.newReplyNotification = newReplyNotification;
                this.localPostNotification = localPostNotification;
+               this.localReplyNotification = localReplyNotification;
                formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
 
                this.templateContextFactory = templateContextFactory;
                templateContextFactory.addTemplateObject("webInterface", this);
                templateContextFactory.addTemplateObject("formPassword", formPassword);
-
-               /* create notifications. */
-               Template newReplyNotificationTemplate = loaders.loadTemplate("/templates/notify/newReplyNotification.html");
-               newReplyNotification = new ListNotification<>("new-reply-notification", "replies", newReplyNotificationTemplate, false);
-
-               Template localReplyNotificationTemplate = loaders.loadTemplate("/templates/notify/newReplyNotification.html");
-               localReplyNotification = new ListNotification<>("local-reply-notification", "replies", localReplyNotificationTemplate, false);
        }
 
        //
@@ -511,61 +508,6 @@ public class WebInterface implements SessionProvider {
                }
        }
 
-       //
-       // EVENT HANDLERS
-       //
-
-       /**
-        * Notifies the web interface that a new {@link PostReply} was found.
-        *
-        * @param newPostReplyFoundEvent
-        *            The event
-        */
-       @Subscribe
-       public void newReplyFound(NewPostReplyFoundEvent newPostReplyFoundEvent) {
-               PostReply reply = newPostReplyFoundEvent.getPostReply();
-               boolean isLocal = reply.getSone().isLocal();
-               if (isLocal) {
-                       localReplyNotification.add(reply);
-               } else {
-                       newReplyNotification.add(reply);
-               }
-               if (!hasFirstStartNotification()) {
-                       notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification);
-               } else {
-                       getCore().markReplyKnown(reply);
-               }
-       }
-
-       @Subscribe
-       public void markPostKnown(MarkPostKnownEvent markPostKnownEvent) {
-               removePost(markPostKnownEvent.getPost());
-       }
-
-       @Subscribe
-       public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) {
-               removeReply(markPostReplyKnownEvent.getPostReply());
-       }
-
-       @Subscribe
-       public void postRemoved(PostRemovedEvent postRemovedEvent) {
-               removePost(postRemovedEvent.getPost());
-       }
-
-       private void removePost(Post post) {
-               newPostNotification.remove(post);
-       }
-
-       @Subscribe
-       public void replyRemoved(PostReplyRemovedEvent postReplyRemovedEvent) {
-               removeReply(postReplyRemovedEvent.getPostReply());
-       }
-
-       private void removeReply(PostReply reply) {
-               newReplyNotification.remove(reply);
-               localReplyNotification.remove(reply);
-       }
-
        /**
         * Notifies the web interface that a {@link Sone} is being inserted.
         *