From 464fee6c08c68ad2b5f76ad5d9d32fcd545713c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 2 Dec 2014 21:34:59 +0100 Subject: [PATCH] Iterate over IDs and load Sones correctly. --- .../pterodactylus/sone/web/ajax/GetStatusAjaxPage.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java index 89a3858..bb59a8d 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -21,6 +21,7 @@ import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -33,6 +34,7 @@ import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.notify.ListNotificationFilters; import net.pterodactylus.sone.template.SoneAccessor; +import net.pterodactylus.sone.utils.Optionals; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.notify.Notification; @@ -43,6 +45,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; +import com.google.common.collect.FluentIterable; /** * The “get status” AJAX handler returns all information that is necessary to @@ -76,16 +79,14 @@ public class GetStatusAjaxPage extends JsonPage { String loadSoneIds = request.getHttpRequest().getParam("soneIds"); if (loadSoneIds.length() > 0) { String[] soneIds = loadSoneIds.split(","); - for (String soneId : soneIds) { - /* just add it, we skip null further down. */ - sones.add(webInterface.getCore().getSone(soneId).orNull()); - } + FluentIterable.from(Arrays.asList(soneIds)) + .transform(webInterface.getCore().soneLoader()) + .filter(Optionals.isPresent()) + .transform(Optionals.get()) + .copyInto(sones); } ArrayNode jsonSones = new ArrayNode(instance); for (Sone sone : sones) { - if (sone == null) { - continue; - } jsonSones.add(createJsonSone(sone)); } /* load notifications. */ -- 2.7.4