X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetStatusAjaxPage.java;h=25c87133113e2b26a6e2ae9be1c01258028805bc;hb=99888ce13cc17d49f5e217ab6f2c9ad5ef168792;hp=28fee14135947f78952ce118d4f3a856cb28ab81;hpb=480691a26222e035e53bda56029524e160fdf898;p=Sone.git 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 28fee14..25c8713 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -1,5 +1,5 @@ /* - * Sone - GetStatusAjaxPage.java - Copyright © 2010–2012 David Roden + * Sone - GetStatusAjaxPage.java - Copyright © 2010–2013 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web.ajax; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashSet; @@ -32,13 +33,14 @@ import net.pterodactylus.sone.notify.ListNotificationFilters; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.collection.filter.Filter; -import net.pterodactylus.util.collection.filter.Filters; import net.pterodactylus.util.json.JsonArray; import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.object.HashCode; +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; + /** * The “get status” AJAX handler returns all information that is necessary to * update the web interface in real-time. @@ -66,19 +68,14 @@ public class GetStatusAjaxPage extends JsonPage { @Override protected JsonObject createJsonObject(FreenetRequest request) { final Sone currentSone = getCurrentSone(request.getToadletContext(), false); - /* load Sones. */ - boolean loadAllSones = Boolean.parseBoolean(request.getHttpRequest().getParam("loadAllSones", "false")); + /* load Sones. always return the status of the current Sone. */ Set sones = new HashSet(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)); - } + 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(); @@ -91,14 +88,15 @@ public class GetStatusAjaxPage extends JsonPage { } /* load notifications. */ List notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone); + Collections.sort(notifications, Notification.CREATED_TIME_SORTER); int notificationHash = HashCode.hashCode(notifications); /* load new posts. */ - Set newPosts = webInterface.getNewPosts(); + Collection newPosts = webInterface.getNewPosts(); if (currentSone != null) { - newPosts = Filters.filteredSet(newPosts, new Filter() { + newPosts = Collections2.filter(newPosts, new Predicate() { @Override - public boolean filterObject(Post post) { + public boolean apply(Post post) { return ListNotificationFilters.isPostVisible(currentSone, post); } @@ -114,22 +112,22 @@ public class GetStatusAjaxPage extends JsonPage { jsonPosts.add(jsonPost); } /* load new replies. */ - Set newReplies = webInterface.getNewReplies(); + Collection newReplies = webInterface.getNewReplies(); if (currentSone != null) { - newReplies = Filters.filteredSet(newReplies, new Filter() { + newReplies = Collections2.filter(newReplies, new Predicate() { @Override - public boolean filterObject(PostReply reply) { + public boolean apply(PostReply reply) { return ListNotificationFilters.isReplyVisible(currentSone, reply); } }); } /* remove replies to unknown posts. */ - newReplies = Filters.filteredSet(newReplies, new Filter() { + newReplies = Collections2.filter(newReplies, new Predicate() { @Override - public boolean filterObject(PostReply reply) { + public boolean apply(PostReply reply) { return (reply.getPost() != null) && (reply.getPost().getSone() != null); } }); @@ -197,7 +195,7 @@ public class GetStatusAjaxPage extends JsonPage { * The current Sone (may be {@code null}) * @return The current options */ - private JsonObject createJsonOptions(Sone currentSone) { + private static JsonObject createJsonOptions(Sone currentSone) { JsonObject options = new JsonObject(); if (currentSone != null) { options.put("ShowNotification/NewSones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());