import java.util.List;
import net.pterodactylus.sone.core.Preferences;
-import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.LocalSone;
import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
import net.pterodactylus.sone.web.page.FreenetRequest;
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.
*
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<LocalSone> currentSone = webInterface.getCurrentSone(request.getToadletContext(), false);
if (request.getMethod() == Method.POST) {
List<String> fieldErrors = new ArrayList<String>();
- 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);
}
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());