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;
* @return The currently logged in Sone, or {@code null} if no Sone is
* currently logged in
*/
- protected Sone getCurrentSone(ToadletContext toadletContext) {
+ protected Optional<Sone> getCurrentSone(ToadletContext toadletContext) {
return webInterface.getCurrentSone(toadletContext);
}
* @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<Sone> getCurrentSone(ToadletContext toadletContext, boolean create) {
return webInterface.getCurrentSone(toadletContext, create);
}
@Override
protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
super.processTemplate(request, templateContext);
- Sone currentSone = getCurrentSone(request.getToadletContext(), false);
+ Optional<Sone> 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);
templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition());
templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
- List<Notification> notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone);
+ List<Notification> notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone.orNull());
Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
templateContext.set("notifications", notifications);
templateContext.set("notificationHash", notifications.hashCode());
*/
@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()) {
return false;
}
if (requiresLogin()) {
- return getCurrentSone(toadletContext, false) != null;
+ return getCurrentSone(toadletContext, false).isPresent();
}
return true;
}