X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FOptionsPage.java;h=cbc96869acbfb987deb20e05f1973b18153a27c0;hp=c38f97b8de955c29dd375eed6c3c797d1bd88470;hb=53a71d1d6b91e4d56af49a06f2e06bc4d11bf3eb;hpb=1a2c9eb50e89d9ba5f9ea9b72721ebfeb68650cd diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java index c38f97b..cbc9686 100644 --- a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java +++ b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java @@ -31,6 +31,8 @@ import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.web.Method; +import com.google.common.base.Optional; + /** * This page lets the user edit the options of the Sone plugin. * @@ -61,22 +63,22 @@ public class OptionsPage extends SoneTemplatePage { protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Preferences preferences = webInterface.getCore().getPreferences(); - Sone currentSone = webInterface.getCurrentSone(request.getToadletContext(), false); + Optional currentSone = webInterface.getCurrentSone(request.getToadletContext(), false); if (request.getMethod() == Method.POST) { List fieldErrors = new ArrayList(); - if (currentSone != null) { + if (currentSone.isPresent()) { boolean autoFollow = request.getHttpRequest().isPartSet("auto-follow"); - currentSone.getOptions().setAutoFollow(autoFollow); + currentSone.get().getOptions().setAutoFollow(autoFollow); boolean enableSoneInsertNotifications = request.getHttpRequest().isPartSet("enable-sone-insert-notifications"); - currentSone.getOptions().setSoneInsertNotificationEnabled(enableSoneInsertNotifications); + currentSone.get().getOptions().setSoneInsertNotificationEnabled(enableSoneInsertNotifications); boolean showNotificationNewSones = request.getHttpRequest().isPartSet("show-notification-new-sones"); - currentSone.getOptions().setShowNewSoneNotifications(showNotificationNewSones); + currentSone.get().getOptions().setShowNewSoneNotifications(showNotificationNewSones); boolean showNotificationNewPosts = request.getHttpRequest().isPartSet("show-notification-new-posts"); - currentSone.getOptions().setShowNewPostNotifications(showNotificationNewPosts); + currentSone.get().getOptions().setShowNewPostNotifications(showNotificationNewPosts); boolean showNotificationNewReplies = request.getHttpRequest().isPartSet("show-notification-new-replies"); - currentSone.getOptions().setShowNewReplyNotifications(showNotificationNewReplies); + currentSone.get().getOptions().setShowNewReplyNotifications(showNotificationNewReplies); String showCustomAvatars = request.getHttpRequest().getPartAsStringFailsafe("show-custom-avatars", 32); - currentSone.getOptions().setShowCustomAvatars(ShowCustomAvatars.valueOf(showCustomAvatars)); + currentSone.get().getOptions().setShowCustomAvatars(ShowCustomAvatars.valueOf(showCustomAvatars)); webInterface.getCore().touchConfiguration(); } Integer insertionDelay = parseInt(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16), null); @@ -139,13 +141,13 @@ public class OptionsPage extends SoneTemplatePage { } templateContext.set("fieldErrors", fieldErrors); } - if (currentSone != null) { - templateContext.set("auto-follow", currentSone.getOptions().isAutoFollow()); - templateContext.set("enable-sone-insert-notifications", currentSone.getOptions().isSoneInsertNotificationEnabled()); - templateContext.set("show-notification-new-sones", currentSone.getOptions().isShowNewSoneNotifications()); - templateContext.set("show-notification-new-posts", currentSone.getOptions().isShowNewPostNotifications()); - templateContext.set("show-notification-new-replies", currentSone.getOptions().isShowNewReplyNotifications()); - templateContext.set("show-custom-avatars", currentSone.getOptions().getShowCustomAvatars().name()); + if (currentSone.isPresent()) { + templateContext.set("auto-follow", currentSone.get().getOptions().isAutoFollow()); + templateContext.set("enable-sone-insert-notifications", currentSone.get().getOptions().isSoneInsertNotificationEnabled()); + templateContext.set("show-notification-new-sones", currentSone.get().getOptions().isShowNewSoneNotifications()); + templateContext.set("show-notification-new-posts", currentSone.get().getOptions().isShowNewPostNotifications()); + templateContext.set("show-notification-new-replies", currentSone.get().getOptions().isShowNewReplyNotifications()); + templateContext.set("show-custom-avatars", currentSone.get().getOptions().getShowCustomAvatars().name()); } templateContext.set("insertion-delay", preferences.getInsertionDelay()); templateContext.set("posts-per-page", preferences.getPostsPerPage());