X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebInterface.java;h=e18521c947f98dabd2b50e43b776da36ae06f2c0;hb=2cee36b47bf421ab43be6ca5a6be7fdb67441418;hp=58962c431dad0e8fa20fbbad0614d2d4bbf63691;hpb=80234092aa0640a19fb14fb303644c769e372ec6;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 58962c4..e18521c 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -36,6 +36,7 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.core.CoreListener; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.L10nFilter; @@ -48,6 +49,7 @@ import net.pterodactylus.sone.template.GetPagePlugin; import net.pterodactylus.sone.template.IdentityAccessor; import net.pterodactylus.sone.template.NotificationManagerAccessor; import net.pterodactylus.sone.template.PostAccessor; +import net.pterodactylus.sone.template.ProfileAccessor; import net.pterodactylus.sone.template.ReplyAccessor; import net.pterodactylus.sone.template.RequestChangeFilter; import net.pterodactylus.sone.template.SoneAccessor; @@ -88,6 +90,7 @@ import net.pterodactylus.util.template.TemplateFactory; import net.pterodactylus.util.template.TemplateProvider; import net.pterodactylus.util.template.XmlFilter; import net.pterodactylus.util.thread.Ticker; +import net.pterodactylus.util.version.Version; import freenet.clients.http.SessionManager; import freenet.clients.http.SessionManager.Session; import freenet.clients.http.ToadletContainer; @@ -141,6 +144,9 @@ public class WebInterface implements CoreListener { /** The “Sone locked” notification. */ private final ListNotification lockedSonesNotification; + /** The “new version” notification. */ + private final TemplateNotification newVersionNotification; + /** * Creates a new web interface. * @@ -155,6 +161,7 @@ public class WebInterface implements CoreListener { templateFactory.addAccessor(Object.class, new ReflectionAccessor()); templateFactory.addAccessor(Collection.class, new CollectionAccessor()); templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore())); + templateFactory.addAccessor(Profile.class, new ProfileAccessor()); templateFactory.addAccessor(Post.class, new PostAccessor(getCore(), templateFactory)); templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore(), templateFactory)); templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore())); @@ -189,6 +196,9 @@ public class WebInterface implements CoreListener { Template lockedSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/lockedSonesNotification.html")); lockedSonesNotification = new ListNotification("sones-locked-notification", "sones", lockedSonesTemplate); + + Template newVersionTemplate = templateFactory.createTemplate(createReader("/templates/notify/newVersionNotification.html")); + newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate); } // @@ -246,7 +256,22 @@ public class WebInterface implements CoreListener { * currently logged in */ public Sone getCurrentSone(ToadletContext toadletContext) { - return getCurrentSone(getCurrentSession(toadletContext)); + return getCurrentSone(toadletContext, true); + } + + /** + * Returns the currently logged in Sone. + * + * @param toadletContext + * The toadlet context + * @param create + * {@code true} to create a new session if no session exists, + * {@code false} to not create a new session + * @return The currently logged in Sone, or {@code null} if no Sone is + * currently logged in + */ + public Sone getCurrentSone(ToadletContext toadletContext, boolean create) { + return getCurrentSone(getCurrentSession(toadletContext, create)); } /** @@ -647,7 +672,7 @@ public class WebInterface implements CoreListener { */ @Override public void postRemoved(Post post) { - /* TODO */ + newPostNotification.remove(post); } /** @@ -655,7 +680,7 @@ public class WebInterface implements CoreListener { */ @Override public void replyRemoved(Reply reply) { - /* TODO */ + newReplyNotification.remove(reply); } /** @@ -669,6 +694,7 @@ public class WebInterface implements CoreListener { @SuppressWarnings("synthetic-access") public void run() { lockedSonesNotification.add(sone); + lockedSonesTickerObjects.remove(sone); notificationManager.addNotification(lockedSonesNotification); } }, "Sone Locked Notification"); @@ -680,12 +706,18 @@ public class WebInterface implements CoreListener { */ @Override public void soneUnlocked(Sone sone) { - Object tickerObject = lockedSonesTickerObjects.remove(sone); - if (tickerObject == null) { - return; - } lockedSonesNotification.remove(sone); - Ticker.getInstance().deregisterEvent(tickerObject); + Ticker.getInstance().deregisterEvent(lockedSonesTickerObjects.remove(sone)); + } + + /** + * {@inheritDoc} + */ + @Override + public void updateFound(Version version, long releaseTime) { + newVersionNotification.set("version", version); + newVersionNotification.set("releaseTime", releaseTime); + notificationManager.addNotification(newVersionNotification); } /**