X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FSoneTemplatePage.java;h=fa2798e762adf37462bf5a813ea13debd6328899;hp=e18e1a418e6b429a0db56b4863dfa45cf8697ac5;hb=53a71d1d6b91e4d56af49a06f2e06bc4d11bf3eb;hpb=1a2c9eb50e89d9ba5f9ea9b72721ebfeb68650cd diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index e18e1a4..fa2798e 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -34,6 +34,7 @@ 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; @@ -137,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); } @@ -152,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); } @@ -223,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); @@ -233,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()); @@ -244,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()) { @@ -286,7 +287,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { return false; } if (requiresLogin()) { - return getCurrentSone(toadletContext, false) != null; + return getCurrentSone(toadletContext, false).isPresent(); } return true; }