X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetNotificationsAjaxPage.java;h=e6a6a9f9f6eeb41c00ddbb3dccf61911e144e92c;hb=30ef483c663ded175b66b50b652a0497e04bd493;hp=a25e6658c85c499085c554c539799f95d6d14f4f;hpb=e25b3f1ea99a8dffc55efe4b68246937a55ebd33;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java index a25e665..e6a6a9f 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java @@ -25,7 +25,7 @@ import java.util.Collection; 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; @@ -37,6 +37,7 @@ import net.pterodactylus.util.template.TemplateContext; 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. @@ -80,9 +81,9 @@ public class GetNotificationsAjaxPage extends JsonPage { */ @Override protected JsonReturnObject createJsonObject(FreenetRequest request) { - Sone currentSone = getCurrentSone(request.getToadletContext(), false); + Optional currentSone = getCurrentSone(request.getToadletContext(), false); Collection notifications = webInterface.getNotifications().getNotifications(); - List filteredNotifications = ListNotificationFilters.filterNotifications(notifications, currentSone); + List filteredNotifications = ListNotificationFilters.filterNotifications(notifications, currentSone.orNull()); Collections.sort(filteredNotifications, Notification.CREATED_TIME_SORTER); ArrayNode jsonNotifications = new ArrayNode(instance); for (Notification notification : filteredNotifications) { @@ -144,12 +145,12 @@ public class GetNotificationsAjaxPage extends JsonPage { * The current Sone (may be {@code null}) * @return The current options */ - private static JsonNode createJsonOptions(Sone currentSone) { + private static JsonNode createJsonOptions(Optional currentSone) { ObjectNode options = new ObjectNode(instance); - if (currentSone != null) { - options.put("ShowNotification/NewSones", currentSone.getOptions().isShowNewSoneNotifications()); - options.put("ShowNotification/NewPosts", currentSone.getOptions().isShowNewPostNotifications()); - options.put("ShowNotification/NewReplies", currentSone.getOptions().isShowNewReplyNotifications()); + 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; }