X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FGetStatusAjaxPage.java;h=8657a6a97060f27a51a8336996ce86759392b99d;hb=274784c1ae880b7cdc2bb7cf31d75e4092ec5653;hp=28fee14135947f78952ce118d4f3a856cb28ab81;hpb=0acd68634f3e73c62087609c1faa2dfc53da506d;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..8657a6a 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,12 +33,12 @@ 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 @@ -66,19 +67,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 +87,14 @@ public class GetStatusAjaxPage extends JsonPage { } /* load notifications. */ List notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone); - int notificationHash = HashCode.hashCode(notifications); + Collections.sort(notifications, Notification.CREATED_TIME_SORTER); /* 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 +110,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); } }); @@ -142,7 +138,7 @@ public class GetStatusAjaxPage extends JsonPage { jsonReply.put("postSone", reply.getPost().getSone().getId()); jsonReplies.add(jsonReply); } - return createSuccessJsonObject().put("loggedIn", currentSone != null).put("options", createJsonOptions(currentSone)).put("sones", jsonSones).put("notificationHash", notificationHash).put("newPosts", jsonPosts).put("newReplies", jsonReplies); + return createSuccessJsonObject().put("loggedIn", currentSone != null).put("options", createJsonOptions(currentSone)).put("sones", jsonSones).put("notificationHash", notifications.hashCode()).put("newPosts", jsonPosts).put("newReplies", jsonReplies); } /** @@ -197,7 +193,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());