import java.util.Collections;
import java.util.List;
-import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.LocalSone;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.sone.notify.ListNotificationFilters;
import net.pterodactylus.sone.web.WebInterface;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Optional;
/**
* AJAX handler to return all current notifications.
*/
@Override
protected JsonReturnObject createJsonObject(FreenetRequest request) {
- Sone currentSone = getCurrentSone(request.getToadletContext(), false);
+ Optional<LocalSone> currentSone = getCurrentSone(request.getToadletContext(), false);
Collection<Notification> notifications = webInterface.getNotifications().getNotifications();
- List<Notification> filteredNotifications = ListNotificationFilters.filterNotifications(notifications, currentSone);
+ List<Notification> filteredNotifications = ListNotificationFilters.filterNotifications(notifications, currentSone.orNull());
Collections.sort(filteredNotifications, Notification.CREATED_TIME_SORTER);
ArrayNode jsonNotifications = new ArrayNode(instance);
for (Notification notification : filteredNotifications) {
* The current Sone (may be {@code null})
* @return The current options
*/
- private static JsonNode createJsonOptions(Sone currentSone) {
+ private static JsonNode createJsonOptions(Optional<LocalSone> currentSone) {
ObjectNode options = new ObjectNode(instance);
- if (currentSone != null) {
- options.put("ShowNotification/NewSones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
- options.put("ShowNotification/NewPosts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
- options.put("ShowNotification/NewReplies", currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
+ if (currentSone.isPresent()) {
+ options.put("ShowNotification/NewSones", currentSone.get().getOptions().isShowNewSoneNotifications());
+ options.put("ShowNotification/NewPosts", currentSone.get().getOptions().isShowNewPostNotifications());
+ options.put("ShowNotification/NewReplies", currentSone.get().getOptions().isShowNewReplyNotifications());
}
return options;
}