/*
- * Sone - WebInterface.java - Copyright © 2010–2013 David Roden
+ * Sone - WebInterface.java - Copyright © 2010–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
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;
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;
import net.pterodactylus.sone.main.ReparseFilter;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.sone.notify.ListNotification;
+import net.pterodactylus.sone.notify.ListNotificationFilters;
+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;
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;
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.
/** The parser filter. */
private final ParserFilter parserFilter;
+ private final ListNotificationFilters listNotificationFilters;
+ private final PostVisibilityFilter postVisibilityFilter;
+ private final ReplyVisibilityFilter replyVisibilityFilter;
+
/** The “new Sone” notification. */
private final ListNotification<Sone> newSoneNotification;
* The Sone plugin
*/
@Inject
- public WebInterface(SonePlugin sonePlugin, Loaders loaders) {
+ public WebInterface(SonePlugin sonePlugin, Loaders loaders, ListNotificationFilters listNotificationFilters, PostVisibilityFilter postVisibilityFilter, ReplyVisibilityFilter replyVisibilityFilter) {
this.sonePlugin = sonePlugin;
this.loaders = loaders;
+ this.listNotificationFilters = listNotificationFilters;
+ this.postVisibilityFilter = postVisibilityFilter;
+ this.replyVisibilityFilter = replyVisibilityFilter;
formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
soneTextParser = new SoneTextParser(getCore(), getCore());
return notificationManager;
}
+ @Nonnull
+ public Optional<Notification> getNotification(@Nonnull String notificationId) {
+ return Optional.fromNullable(notificationManager.getNotification(notificationId));
+ }
+
+ @Nonnull
+ public Collection<Notification> getNotifications(@Nullable Sone currentSone) {
+ return listNotificationFilters.filterNotifications(notificationManager.getNotifications(), currentSone);
+ }
+
/**
* Returns the l10n helper of the node.
*
return ImmutableSet.<Post> builder().addAll(newPostNotification.getElements()).addAll(localPostNotification.getElements()).build();
}
+ @Nonnull
+ public Collection<Post> getNewPosts(@Nullable Sone currentSone) {
+ Set<Post> allNewPosts = ImmutableSet.<Post> 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}.
return ImmutableSet.<PostReply> builder().addAll(newReplyNotification.getElements()).addAll(localReplyNotification.getElements()).build();
}
+ @Nonnull
+ public Collection<PostReply> getNewReplies(@Nullable Sone currentSone) {
+ Set<PostReply> allNewReplies = ImmutableSet.<PostReply>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.
PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
pageToadlets.add(pageToadletFactory.createPageToadlet(new RedirectPage<FreenetRequest>("", "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"));
*/
@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);
}