X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FSoneTemplatePage.java;h=fa2798e762adf37462bf5a813ea13debd6328899;hb=53a71d1d6b91e4d56af49a06f2e06bc4d11bf3eb;hp=7dfdfe76a387b7947108a672930b16f7b4d61b85;hpb=274784c1ae880b7cdc2bb7cf31d75e4092ec5653;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index 7dfdfe7..fa2798e 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -34,10 +34,10 @@ import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import freenet.clients.http.SessionManager.Session; import freenet.clients.http.ToadletContext; import freenet.support.api.HTTPRequest; @@ -131,35 +131,6 @@ public class SoneTemplatePage extends FreenetTemplatePage { // /** - * Returns the current session, creating a new session if there is no - * current session. - * - * @param toadletContenxt - * The toadlet context - * @return The current session, or {@code null} if there is no current - * session - */ - protected Session getCurrentSession(ToadletContext toadletContenxt) { - return webInterface.getCurrentSession(toadletContenxt); - } - - /** - * Returns the current session, creating a new session if there is no - * current session and {@code create} is {@code true}. - * - * @param toadletContenxt - * The toadlet context - * @param create - * {@code true} to create a new session if there is no current - * session, {@code false} otherwise - * @return The current session, or {@code null} if there is no current - * session - */ - protected Session getCurrentSession(ToadletContext toadletContenxt, boolean create) { - return webInterface.getCurrentSession(toadletContenxt, create); - } - - /** * Returns the currently logged in Sone. * * @param toadletContext @@ -167,7 +138,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { * @return The currently logged in Sone, or {@code null} if no Sone is * currently logged in */ - protected Sone getCurrentSone(ToadletContext toadletContext) { + protected Optional getCurrentSone(ToadletContext toadletContext) { return webInterface.getCurrentSone(toadletContext); } @@ -182,7 +153,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { * @return The currently logged in Sone, or {@code null} if no Sone is * currently logged in */ - protected Sone getCurrentSone(ToadletContext toadletContext, boolean create) { + protected Optional getCurrentSone(ToadletContext toadletContext, boolean create) { return webInterface.getCurrentSone(toadletContext, create); } @@ -253,9 +224,9 @@ public class SoneTemplatePage extends FreenetTemplatePage { @Override protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); - Sone currentSone = getCurrentSone(request.getToadletContext(), false); + Optional currentSone = getCurrentSone(request.getToadletContext(), false); templateContext.set("core", webInterface.getCore()); - templateContext.set("currentSone", currentSone); + templateContext.set("currentSone", currentSone.orNull()); templateContext.set("localSones", webInterface.getCore().getLocalSones()); templateContext.set("request", request); templateContext.set("currentVersion", SonePlugin.VERSION); @@ -263,7 +234,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition()); templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion()); templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate()); - List notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone); + List notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone.orNull()); Collections.sort(notifications, Notification.CREATED_TIME_SORTER); templateContext.set("notifications", notifications); templateContext.set("notificationHash", notifications.hashCode()); @@ -274,7 +245,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { */ @Override protected String getRedirectTarget(FreenetRequest request) { - if (requiresLogin() && (getCurrentSone(request.getToadletContext(), false) == null)) { + if (requiresLogin() && !getCurrentSone(request.getToadletContext(), false).isPresent()) { HTTPRequest httpRequest = request.getHttpRequest(); String originalUrl = httpRequest.getPath(); if (httpRequest.hasParameters()) { @@ -316,7 +287,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { return false; } if (requiresLogin()) { - return getCurrentSone(toadletContext, false) != null; + return getCurrentSone(toadletContext, false).isPresent(); } return true; }