for (String soneId : soneIds) {
/* just add it, we skip null further down. */
sones.add(webInterface.getCore().getSone(soneId).orNull());
}
}
ArrayNode jsonSones = new ArrayNode(instance);
for (Sone sone : sones) {
if (sone == null) {
continue;
}
jsonSones.add(createJsonSone(sone));
}
/* load notifications. */
List<Notification> notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone);
Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
/* load new posts. */
Collection<Post> newPosts = webInterface.getNewPosts();
if (currentSone != null) {
newPosts = Collections2.filter(newPosts, new Predicate<Post>() {
@Override
public boolean apply(Post post) {
return ListNotificationFilters.isPostVisible(currentSone, post);
}
});
}
ArrayNode jsonPosts = new ArrayNode(instance);
for (Post post : newPosts) {
ObjectNode jsonPost = new ObjectNode(instance);
jsonPost.put("id", post.getId());
jsonPost.put("sone", post.getSone().getId());
jsonPost.put("recipient", post.getRecipientId().orNull());
jsonPost.put("time", post.getTime());
jsonPosts.add(jsonPost);
}
/* load new replies. */
Collection<PostReply> newReplies = webInterface.getNewReplies();
if (currentSone != null) {
newReplies = Collections2.filter(newReplies, new Predicate<PostReply>() {
@Override
public boolean apply(PostReply reply) {
return ListNotificationFilters.isReplyVisible(currentSone, reply);
}
});
}
/* remove replies to unknown posts. */
newReplies = Collections2.filter(newReplies, PostReply.HAS_POST_FILTER);
ArrayNode jsonReplies = new ArrayNode(instance);
for (PostReply reply : newReplies) {
ObjectNode jsonReply = new ObjectNode(instance);
jsonReply.put("id", reply.getId());
jsonReply.put("sone", reply.getSone().getId());
jsonReply.put("post", reply.getPostId());
jsonReply.put("postSone", reply.getPost().get().getSone().getId());
jsonReplies.add(jsonReply);
}
return createSuccessJsonObject().put("loggedIn", currentSone != null).put("options", createJsonOptions(currentSone)).put("sones", jsonSones).put("notificationHash", notifications.hashCode()).put("newPosts", jsonPosts).put("newReplies", jsonReplies);
}