import java.util.Collections;
import java.util.List;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.notify.ListNotificationFilters;
import net.pterodactylus.util.notify.Notification;
import net.pterodactylus.util.notify.NotificationManager;
import net.pterodactylus.util.template.ReflectionAccessor;
public Object get(TemplateContext templateContext, Object object, String member) {
NotificationManager notificationManager = (NotificationManager) object;
if ("all".equals(member)) {
- List<Notification> notifications = new ArrayList<Notification>(notificationManager.getNotifications());
+ List<Notification> notifications = ListNotificationFilters.filterNotifications(new ArrayList<Notification>(notificationManager.getNotifications()), (Sone) templateContext.get("currentSone"));
Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
return notifications;
- } else if ("new".equals(member)) {
- List<Notification> notifications = new ArrayList<Notification>(notificationManager.getChangedNotifications());
- Collections.sort(notifications, Notification.LAST_UPDATED_TIME_SORTER);
- return notifications;
}
return super.get(templateContext, object, member);
}
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;
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;
*/
@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<Sone> sones = new HashSet<Sone>(Collections.singleton(getCurrentSone(request.getToadletContext(), false)));
jsonSones.add(jsonSone);
}
/* load notifications. */
- List<Notification> notifications = new ArrayList<Notification>(webInterface.getNotifications().getChangedNotifications());
- Set<Notification> removedNotifications = webInterface.getNotifications().getRemovedNotifications();
+ List<Notification> notifications = ListNotificationFilters.filterNotifications(new ArrayList<Notification>(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<Post> newPosts = webInterface.getNewPosts();
+ if (currentSone != null) {
+ newPosts = Filters.filteredSet(newPosts, new Filter<Post>() {
+
+ @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();
}
/* load new replies. */
Set<Reply> newReplies = webInterface.getNewReplies();
+ if (currentSone != null) {
+ newReplies = Filters.filteredSet(newReplies, new Filter<Reply>() {
+
+ @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();
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);
}
/**
$.each(data.sones, function(index, value) {
updateSoneStatus(value.id, value.name, value.status, value.modified, value.locked, value.lastUpdatedUnknown ? null : value.lastUpdated);
});
+ /* search for removed notifications. */
+ $("#sone #notification-area .notification").each(function() {
+ notificationId = $(this).attr("id");
+ foundNotification = false;
+ $.each(data.notifications, function(index, value) {
+ if (value.id == notificationId) {
+ foundNotification = true;
+ return false;
+ }
+ });
+ if (!foundNotification) {
+ $(this).slideUp("normal", function() {
+ $(this).remove();
+ });
+ }
+ });
/* process notifications. */
$.each(data.notifications, function(index, value) {
oldNotification = $("#sone #notification-area .notification#" + value.id);
} else {
$("#sone #notification-area").append(notification);
notification.slideDown();
+ setActivity();
}
- setActivity();
- });
- $.each(data.removedNotifications, function(index, value) {
- $("#sone #notification-area .notification#" + value.id).slideUp();
});
/* process new posts. */
$.each(data.newPosts, function(index, value) {