X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebInterface.java;h=f08ad5dbd5969aa3ed1ea1114a6bd04fe4f7e370;hp=4da21779739268028f8272561816a709a8559099;hb=662bcd45433c0ab480ad0e52f3e72e9e886bdfc6;hpb=1e9a08c2b73b16dc178437eb8c8025aaa083fcca diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 4da2177..f08ad5d 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import static com.google.common.collect.FluentIterable.from; import static java.util.logging.Logger.getLogger; import static net.pterodactylus.util.template.TemplateParser.parse; @@ -37,6 +38,8 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.core.event.ImageInsertAbortedEvent; @@ -72,6 +75,9 @@ import net.pterodactylus.sone.main.Loaders; import net.pterodactylus.sone.main.ReparseFilter; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.notify.ListNotification; +import net.pterodactylus.sone.notify.ListNotificationFilter; +import net.pterodactylus.sone.notify.PostVisibilityFilter; +import net.pterodactylus.sone.notify.ReplyVisibilityFilter; import net.pterodactylus.sone.template.AlbumAccessor; import net.pterodactylus.sone.template.CollectionAccessor; import net.pterodactylus.sone.template.CssClassNameFilter; @@ -147,11 +153,6 @@ import net.pterodactylus.util.template.XmlFilter; import net.pterodactylus.util.web.RedirectPage; import net.pterodactylus.util.web.TemplatePage; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableSet; -import com.google.common.eventbus.Subscribe; -import com.google.inject.Inject; - import freenet.clients.http.SessionManager; import freenet.clients.http.SessionManager.Session; import freenet.clients.http.ToadletContainer; @@ -159,6 +160,12 @@ import freenet.clients.http.ToadletContext; import freenet.l10n.BaseL10n; import freenet.support.api.HTTPRequest; +import com.google.common.base.Optional; +import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableSet; +import com.google.common.eventbus.Subscribe; +import com.google.inject.Inject; + /** * Bundles functionality that a web interface of a Freenet plugin needs, e.g. * references to l10n helpers. @@ -194,6 +201,10 @@ public class WebInterface { /** The parser filter. */ private final ParserFilter parserFilter; + private final ListNotificationFilter listNotificationFilter; + private final PostVisibilityFilter postVisibilityFilter; + private final ReplyVisibilityFilter replyVisibilityFilter; + /** The “new Sone” notification. */ private final ListNotification newSoneNotification; @@ -243,9 +254,12 @@ public class WebInterface { * The Sone plugin */ @Inject - public WebInterface(SonePlugin sonePlugin, Loaders loaders) { + public WebInterface(SonePlugin sonePlugin, Loaders loaders, ListNotificationFilter listNotificationFilter, PostVisibilityFilter postVisibilityFilter, ReplyVisibilityFilter replyVisibilityFilter) { this.sonePlugin = sonePlugin; this.loaders = loaders; + this.listNotificationFilter = listNotificationFilter; + this.postVisibilityFilter = postVisibilityFilter; + this.replyVisibilityFilter = replyVisibilityFilter; formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword(); soneTextParser = new SoneTextParser(getCore(), getCore()); @@ -454,6 +468,16 @@ public class WebInterface { return notificationManager; } + @Nonnull + public Optional getNotification(@Nonnull String notificationId) { + return Optional.fromNullable(notificationManager.getNotification(notificationId)); + } + + @Nonnull + public Collection getNotifications(@Nullable Sone currentSone) { + return listNotificationFilter.filterNotifications(notificationManager.getNotifications(), currentSone); + } + /** * Returns the l10n helper of the node. * @@ -491,6 +515,15 @@ public class WebInterface { return ImmutableSet. builder().addAll(newPostNotification.getElements()).addAll(localPostNotification.getElements()).build(); } + @Nonnull + public Collection getNewPosts(@Nullable Sone currentSone) { + Set allNewPosts = ImmutableSet. builder() + .addAll(newPostNotification.getElements()) + .addAll(localPostNotification.getElements()) + .build(); + return from(allNewPosts).filter(postVisibilityFilter.isVisible(currentSone)).toSet(); + } + /** * Returns the replies that have been announced as new in the * {@link #newReplyNotification}. @@ -501,6 +534,15 @@ public class WebInterface { return ImmutableSet. builder().addAll(newReplyNotification.getElements()).addAll(localReplyNotification.getElements()).build(); } + @Nonnull + public Collection getNewReplies(@Nullable Sone currentSone) { + Set allNewReplies = ImmutableSet.builder() + .addAll(newReplyNotification.getElements()) + .addAll(localReplyNotification.getElements()) + .build(); + return from(allNewReplies).filter(replyVisibilityFilter.isVisible(currentSone)).toSet(); + } + /** * Sets whether the current start of the plugin is the first start. It is * considered a first start if the configuration file does not exist. @@ -638,7 +680,7 @@ public class WebInterface { PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/"); pageToadlets.add(pageToadletFactory.createPageToadlet(new RedirectPage("", "index.html"))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index")); + pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this, postVisibilityFilter), "Index")); pageToadlets.add(pageToadletFactory.createPageToadlet(new NewPage(newTemplate, this), "New")); pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone")); pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones")); @@ -754,7 +796,7 @@ public class WebInterface { /* we need no context to find mentioned Sones. */ Set mentionedSones = new HashSet(); try { - for (Part part : soneTextParser.parse(null, new StringReader(text))) { + for (Part part : soneTextParser.parse(null, text)) { if (part instanceof SonePart) { mentionedSones.add(((SonePart) part).getSone()); } @@ -1019,9 +1061,10 @@ public class WebInterface { */ @Subscribe public void updateFound(UpdateFoundEvent updateFoundEvent) { - newVersionNotification.getTemplateContext().set("latestVersion", updateFoundEvent.version()); - newVersionNotification.getTemplateContext().set("latestEdition", updateFoundEvent.latestEdition()); - newVersionNotification.getTemplateContext().set("releaseTime", updateFoundEvent.releaseTime()); + newVersionNotification.set("latestVersion", updateFoundEvent.version()); + newVersionNotification.set("latestEdition", updateFoundEvent.latestEdition()); + newVersionNotification.set("releaseTime", updateFoundEvent.releaseTime()); + newVersionNotification.set("disruptive", updateFoundEvent.disruptive()); notificationManager.addNotification(newVersionNotification); }