X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetStatusAjaxPage.java;h=b10916979d39881e02e54427105e1dc350d6f01e;hp=fd9ae7695b0fcb55d0f55aaa41aa0c9eb3713f12;hb=d615555392317949e47f6367209ee7194f650768;hpb=53c66e56dbf9aa5dc135daefb119d3e154fac787 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 fd9ae76..b109169 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -22,6 +22,7 @@ import java.io.StringWriter; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashSet; @@ -31,8 +32,12 @@ import java.util.Set; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.notify.ListNotification; +import net.pterodactylus.sone.notify.ListNotificationFilters; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.util.filter.Filter; +import net.pterodactylus.util.filter.Filters; import net.pterodactylus.util.json.JsonArray; import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.notify.Notification; @@ -65,6 +70,7 @@ public class GetStatusAjaxPage extends JsonPage { */ @Override protected JsonObject createJsonObject(Request request) { + final Sone currentSone = getCurrentSone(request.getToadletContext(), false); /* load Sones. */ boolean loadAllSones = Boolean.parseBoolean(request.getHttpRequest().getParam("loadAllSones", "true")); Set sones = new HashSet(Collections.singleton(getCurrentSone(request.getToadletContext(), false))); @@ -80,19 +86,24 @@ public class GetStatusAjaxPage extends JsonPage { jsonSones.add(jsonSone); } /* load notifications. */ - List notifications = new ArrayList(webInterface.getNotifications().getChangedNotifications()); - Set removedNotifications = webInterface.getNotifications().getRemovedNotifications(); + List notifications = ListNotificationFilters.filterNotifications(new ArrayList(webInterface.getNotifications().getNotifications()), currentSone); Collections.sort(notifications, Notification.LAST_UPDATED_TIME_SORTER); JsonArray jsonNotifications = new JsonArray(); for (Notification notification : notifications) { jsonNotifications.add(createJsonNotification(notification)); } - JsonArray jsonRemovedNotifications = new JsonArray(); - for (Notification notification : removedNotifications) { - jsonRemovedNotifications.add(createJsonNotification(notification)); - } /* load new posts. */ Set newPosts = webInterface.getNewPosts(); + if (currentSone != null) { + newPosts = Filters.filteredSet(newPosts, new Filter() { + + @Override + public boolean filterObject(Post post) { + return currentSone.hasFriend(post.getSone().getId()) || currentSone.equals(post.getSone()); + } + + }); + } JsonArray jsonPosts = new JsonArray(); for (Post post : newPosts) { JsonObject jsonPost = new JsonObject(); @@ -104,6 +115,16 @@ public class GetStatusAjaxPage extends JsonPage { } /* load new replies. */ Set newReplies = webInterface.getNewReplies(); + if (currentSone != null) { + newReplies = Filters.filteredSet(newReplies, new Filter() { + + @Override + public boolean filterObject(Reply reply) { + return currentSone.hasFriend(reply.getPost().getSone().getId()) || currentSone.equals(reply.getPost().getSone()); + } + + }); + } JsonArray jsonReplies = new JsonArray(); for (Reply reply : newReplies) { JsonObject jsonReply = new JsonObject(); @@ -113,7 +134,7 @@ public class GetStatusAjaxPage extends JsonPage { jsonReply.put("postSone", reply.getPost().getSone().getId()); jsonReplies.add(jsonReply); } - return createSuccessJsonObject().put("sones", jsonSones).put("notifications", jsonNotifications).put("removedNotifications", jsonRemovedNotifications).put("newPosts", jsonPosts).put("newReplies", jsonReplies); + return createSuccessJsonObject().put("sones", jsonSones).put("notifications", jsonNotifications).put("newPosts", jsonPosts).put("newReplies", jsonReplies); } /**