From: David ‘Bombe’ Roden Date: Tue, 2 Dec 2014 20:34:59 +0000 (+0100) Subject: Iterate over IDs and load Sones correctly. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=464fee6c08c68ad2b5f76ad5d9d32fcd545713c6;p=Sone.git Iterate over IDs and load Sones correctly. --- 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. */