♻️ Extract handler for new remote posts
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index a173d16..4ed49df 100644 (file)
@@ -44,6 +44,7 @@ import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.freenet.L10nFilter;
+import net.pterodactylus.sone.freenet.Translation;
 import net.pterodactylus.sone.main.Loaders;
 import net.pterodactylus.sone.main.PluginHomepage;
 import net.pterodactylus.sone.main.PluginVersion;
@@ -68,7 +69,6 @@ import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage;
 import net.pterodactylus.sone.web.ajax.DeleteProfileFieldAjaxPage;
 import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
 import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage;
-import net.pterodactylus.sone.web.ajax.DistrustAjaxPage;
 import net.pterodactylus.sone.web.ajax.EditAlbumAjaxPage;
 import net.pterodactylus.sone.web.ajax.EditImageAjaxPage;
 import net.pterodactylus.sone.web.ajax.EditProfileFieldAjaxPage;
@@ -85,12 +85,10 @@ import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
 import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
 import net.pterodactylus.sone.web.ajax.MarkAsKnownAjaxPage;
 import net.pterodactylus.sone.web.ajax.MoveProfileFieldAjaxPage;
-import net.pterodactylus.sone.web.ajax.TrustAjaxPage;
 import net.pterodactylus.sone.web.ajax.UnbookmarkAjaxPage;
 import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage;
 import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
 import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
-import net.pterodactylus.sone.web.ajax.UntrustAjaxPage;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.sone.web.page.TemplateRenderer;
 import net.pterodactylus.sone.web.pages.*;
@@ -105,7 +103,6 @@ import net.pterodactylus.util.web.TemplatePage;
 import freenet.clients.http.SessionManager;
 import freenet.clients.http.SessionManager.Session;
 import freenet.clients.http.ToadletContext;
-import freenet.l10n.BaseL10n;
 
 import com.codahale.metrics.*;
 import com.google.common.base.Optional;
@@ -127,7 +124,7 @@ public class WebInterface implements SessionProvider {
        private final Loaders loaders;
 
        /** The notification manager. */
-       private final NotificationManager notificationManager = new NotificationManager();
+       private final NotificationManager notificationManager;
 
        /** The Sone plugin. */
        private final SonePlugin sonePlugin;
@@ -158,9 +155,7 @@ public class WebInterface implements SessionProvider {
 
        private final PageToadletRegistry pageToadletRegistry;
        private final MetricRegistry metricRegistry;
-
-       /** The “new Sone” notification. */
-       private final ListNotification<Sone> newSoneNotification;
+       private final Translation translation;
 
        /** The “new post” notification. */
        private final ListNotification<Post> newPostNotification;
@@ -209,7 +204,8 @@ public class WebInterface implements SessionProvider {
                        ParserFilter parserFilter, ShortenFilter shortenFilter,
                        RenderFilter renderFilter,
                        LinkedElementRenderFilter linkedElementRenderFilter,
-                       PageToadletRegistry pageToadletRegistry, MetricRegistry metricRegistry) {
+                       PageToadletRegistry pageToadletRegistry, MetricRegistry metricRegistry, Translation translation, L10nFilter l10nFilter,
+                       NotificationManager notificationManager) {
                this.sonePlugin = sonePlugin;
                this.loaders = loaders;
                this.listNotificationFilter = listNotificationFilter;
@@ -223,18 +219,17 @@ public class WebInterface implements SessionProvider {
                this.linkedElementRenderFilter = linkedElementRenderFilter;
                this.pageToadletRegistry = pageToadletRegistry;
                this.metricRegistry = metricRegistry;
+               this.l10nFilter = l10nFilter;
+               this.translation = translation;
+               this.notificationManager = notificationManager;
                formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
                soneTextParser = new SoneTextParser(getCore(), getCore());
-               l10nFilter = new L10nFilter(getL10n());
 
                this.templateContextFactory = templateContextFactory;
                templateContextFactory.addTemplateObject("webInterface", this);
                templateContextFactory.addTemplateObject("formPassword", formPassword);
 
                /* create notifications. */
-               Template newSoneNotificationTemplate = loaders.loadTemplate("/templates/notify/newSoneNotification.html");
-               newSoneNotification = new ListNotification<>("new-sone-notification", "sones", newSoneNotificationTemplate, false);
-
                Template newPostNotificationTemplate = loaders.loadTemplate("/templates/notify/newPostNotification.html");
                newPostNotification = new ListNotification<>("new-post-notification", "posts", newPostNotificationTemplate, false);
 
@@ -379,13 +374,8 @@ public class WebInterface implements SessionProvider {
                return listNotificationFilter.filterNotifications(notificationManager.getNotifications(), currentSone);
        }
 
-       /**
-        * Returns the l10n helper of the node.
-        *
-        * @return The node’s l10n helper
-        */
-       public BaseL10n getL10n() {
-               return sonePlugin.l10n().getBase();
+       public Translation getTranslation() {
+               return translation;
        }
 
        /**
@@ -577,9 +567,6 @@ public class WebInterface implements SessionProvider {
                pageToadletRegistry.addPage(new UploadImagePage(this, loaders, templateRenderer));
                pageToadletRegistry.addPage(new EditImagePage(this, loaders, templateRenderer));
                pageToadletRegistry.addPage(new DeleteImagePage(this, loaders, templateRenderer));
-               pageToadletRegistry.addPage(new TrustPage(this, loaders, templateRenderer));
-               pageToadletRegistry.addPage(new DistrustPage(this, loaders, templateRenderer));
-               pageToadletRegistry.addPage(new UntrustPage(this, loaders, templateRenderer));
                pageToadletRegistry.addPage(new MarkAsKnownPage(this, loaders, templateRenderer));
                pageToadletRegistry.addPage(new BookmarkPage(this, loaders, templateRenderer));
                pageToadletRegistry.addPage(new UnbookmarkPage(this, loaders, templateRenderer));
@@ -622,9 +609,6 @@ public class WebInterface implements SessionProvider {
                pageToadletRegistry.addPage(new UnfollowSoneAjaxPage(this));
                pageToadletRegistry.addPage(new EditAlbumAjaxPage(this));
                pageToadletRegistry.addPage(new EditImageAjaxPage(this, parserFilter, shortenFilter, renderFilter));
-               pageToadletRegistry.addPage(new TrustAjaxPage(this));
-               pageToadletRegistry.addPage(new DistrustAjaxPage(this));
-               pageToadletRegistry.addPage(new UntrustAjaxPage(this));
                pageToadletRegistry.addPage(new LikeAjaxPage(this));
                pageToadletRegistry.addPage(new UnlikeAjaxPage(this));
                pageToadletRegistry.addPage(new GetLikesAjaxPage(this));
@@ -700,20 +684,6 @@ public class WebInterface implements SessionProvider {
        //
 
        /**
-        * Notifies the web interface that a new {@link Sone} was found.
-        *
-        * @param newSoneFoundEvent
-        *            The event
-        */
-       @Subscribe
-       public void newSoneFound(NewSoneFoundEvent newSoneFoundEvent) {
-               newSoneNotification.add(newSoneFoundEvent.getSone());
-               if (!hasFirstStartNotification()) {
-                       notificationManager.addNotification(newSoneNotification);
-               }
-       }
-
-       /**
         * Notifies the web interface that a new {@link Post} was found.
         *
         * @param newPostFoundEvent
@@ -725,17 +695,15 @@ public class WebInterface implements SessionProvider {
                boolean isLocal = post.getSone().isLocal();
                if (isLocal) {
                        localPostNotification.add(post);
-               } else {
-                       newPostNotification.add(post);
                }
                if (!hasFirstStartNotification()) {
-                       notificationManager.addNotification(isLocal ? localPostNotification : newPostNotification);
+                       if (isLocal) {
+                               notificationManager.addNotification(localPostNotification);
+                       }
                        if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) {
                                mentionNotification.add(post);
                                notificationManager.addNotification(mentionNotification);
                        }
-               } else {
-                       getCore().markPostKnown(post);
                }
        }
 
@@ -765,17 +733,6 @@ public class WebInterface implements SessionProvider {
                }
        }
 
-       /**
-        * Notifies the web interface that a {@link Sone} was marked as known.
-        *
-        * @param markSoneKnownEvent
-        *            The event
-        */
-       @Subscribe
-       public void markSoneKnown(MarkSoneKnownEvent markSoneKnownEvent) {
-               newSoneNotification.remove(markSoneKnownEvent.getSone());
-       }
-
        @Subscribe
        public void markPostKnown(MarkPostKnownEvent markPostKnownEvent) {
                removePost(markPostKnownEvent.getPost());
@@ -787,11 +744,6 @@ public class WebInterface implements SessionProvider {
        }
 
        @Subscribe
-       public void soneRemoved(SoneRemovedEvent soneRemovedEvent) {
-               newSoneNotification.remove(soneRemovedEvent.getSone());
-       }
-
-       @Subscribe
        public void postRemoved(PostRemovedEvent postRemovedEvent) {
                removePost(postRemovedEvent.getPost());
        }