Don’t wrap notifications into an ArrayList.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / GetStatusAjaxPage.java
index 09a9d2b..09b6f40 100644 (file)
@@ -19,7 +19,6 @@ package net.pterodactylus.sone.web.ajax;
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashSet;
@@ -66,10 +65,19 @@ public class GetStatusAjaxPage extends JsonPage {
        protected JsonObject createJsonObject(Request request) {
                final Sone currentSone = getCurrentSone(request.getToadletContext(), false);
                /* load Sones. */
-               boolean loadAllSones = Boolean.parseBoolean(request.getHttpRequest().getParam("loadAllSones", "true"));
+               boolean loadAllSones = Boolean.parseBoolean(request.getHttpRequest().getParam("loadAllSones", "false"));
                Set<Sone> sones = new HashSet<Sone>(Collections.singleton(getCurrentSone(request.getToadletContext(), false)));
                if (loadAllSones) {
                        sones.addAll(webInterface.getCore().getSones());
+               } else {
+                       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, false));
+                               }
+                       }
                }
                JsonArray jsonSones = new JsonArray();
                for (Sone sone : sones) {
@@ -80,7 +88,7 @@ public class GetStatusAjaxPage extends JsonPage {
                        jsonSones.add(jsonSone);
                }
                /* load notifications. */
-               List<Notification> notifications = ListNotificationFilters.filterNotifications(new ArrayList<Notification>(webInterface.getNotifications().getNotifications()), currentSone);
+               List<Notification> notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone);
                Collections.sort(notifications, Notification.LAST_UPDATED_TIME_SORTER);
                JsonArray jsonNotificationInformations = new JsonArray();
                for (Notification notification : notifications) {
@@ -93,7 +101,7 @@ public class GetStatusAjaxPage extends JsonPage {
 
                                @Override
                                public boolean filterObject(Post post) {
-                                       return currentSone.hasFriend(post.getSone().getId()) || currentSone.equals(post.getSone()) || currentSone.equals(post.getRecipient());
+                                       return ListNotificationFilters.isPostVisible(currentSone, post);
                                }
 
                        });
@@ -114,7 +122,7 @@ public class GetStatusAjaxPage extends JsonPage {
 
                                @Override
                                public boolean filterObject(Reply reply) {
-                                       return currentSone.hasFriend(reply.getPost().getSone().getId()) || currentSone.equals(reply.getPost().getSone()) || currentSone.equals(reply.getPost().getRecipient());
+                                       return ListNotificationFilters.isReplyVisible(currentSone, reply);
                                }
 
                        });
@@ -170,7 +178,7 @@ public class GetStatusAjaxPage extends JsonPage {
                synchronized (dateFormat) {
                        jsonSone.put("lastUpdated", dateFormat.format(new Date(sone.getTime())));
                }
-               jsonSone.put("age", (System.currentTimeMillis() - sone.getTime()) / 1000);
+               jsonSone.put("lastUpdatedText", GetTimesAjaxPage.getTime(webInterface, System.currentTimeMillis() - sone.getTime()).getText());
                return jsonSone;
        }