*
* @return The post this reply refers to
*/
- public Post getPost();
+ public Optional<Post> getPost();
/**
* Sets the post this reply refers to.
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
+import com.google.common.base.Optional;
+
/**
* Simple {@link PostReply} implementation.
*
* {@inheritDoc}
*/
@Override
- public Post getPost() {
- return postProvider.getPost(postId).get();
+ public Optional<Post> getPost() {
+ return postProvider.getPost(postId);
}
/**
import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.util.notify.Notification;
+import com.google.common.base.Optional;
+
/**
* Filter for {@link ListNotification}s.
*
*/
public static boolean isReplyVisible(Sone sone, PostReply reply) {
checkNotNull(reply, "reply must not be null");
- Post post = reply.getPost();
- if (post == null) {
+ Optional<Post> post = reply.getPost();
+ if (!post.isPresent()) {
return false;
}
- if (!isPostVisible(sone, post)) {
+ if (!isPostVisible(sone, post.get())) {
return false;
}
if (reply.getTime() > System.currentTimeMillis()) {
import net.pterodactylus.util.template.Filter;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Optional;
+
/**
* {@link Filter} implementation that groups replies by the post the are in
* reply to, returning a map with the post as key and the list of replies as
Map<Post, Set<Sone>> postSones = new HashMap<Post, Set<Sone>>();
Map<Post, Set<PostReply>> postReplies = new HashMap<Post, Set<PostReply>>();
for (PostReply reply : allReplies) {
- Post post = reply.getPost();
- Set<Sone> sones = postSones.get(post);
+ /*
+ * All replies from a new-reply notification have posts,
+ * ListNotificationFilters takes care of that.
+ */
+ Optional<Post> post = reply.getPost();
+ Set<Sone> sones = postSones.get(post.get());
if (sones == null) {
sones = new HashSet<Sone>();
- postSones.put(post, sones);
+ postSones.put(post.get(), sones);
}
sones.add(reply.getSone());
- Set<PostReply> replies = postReplies.get(post);
+ Set<PostReply> replies = postReplies.get(post.get());
if (replies == null) {
replies = new HashSet<PostReply>();
- postReplies.put(post, replies);
+ postReplies.put(post.get(), replies);
}
replies.add(reply);
}
/* collect new elements from notifications. */
Set<Post> posts = new HashSet<Post>(webInterface.getNewPosts());
for (PostReply reply : webInterface.getNewReplies()) {
- posts.add(reply.getPost());
+ posts.add(reply.getPost().get());
}
/* filter and sort them. */
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Optional;
+
/**
* Lets the user browser another Sone.
*
Set<PostReply> replies = sone.getReplies();
final Map<Post, List<PostReply>> repliedPosts = new HashMap<Post, List<PostReply>>();
for (PostReply reply : replies) {
- Post post = reply.getPost();
- if (repliedPosts.containsKey(post) || sone.equals(post.getSone()) || (sone.equals(post.getRecipient()))) {
+ Optional<Post> post = reply.getPost();
+ if (!post.isPresent() || repliedPosts.containsKey(post.get()) || sone.equals(post.get().getSone()) || (sone.equals(post.get().getRecipient()))) {
continue;
}
- repliedPosts.put(post, webInterface.getCore().getReplies(post));
+ repliedPosts.put(post.get(), webInterface.getCore().getReplies(post.get()));
}
List<Post> posts = new ArrayList<Post>(repliedPosts.keySet());
Collections.sort(posts, new Comparator<Post>() {
}
if (!hasFirstStartNotification()) {
notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification);
- if (!getMentionedSones(reply.getText()).isEmpty() && !isLocal && (reply.getPost().getSone() != null) && (reply.getTime() <= System.currentTimeMillis())) {
- mentionNotification.add(reply.getPost());
+ if (!getMentionedSones(reply.getText()).isEmpty() && !isLocal && reply.getPost().isPresent() && (reply.getTime() <= System.currentTimeMillis())) {
+ mentionNotification.add(reply.getPost().get());
notificationManager.addNotification(mentionNotification);
}
} else {
public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) {
newReplyNotification.remove(markPostReplyKnownEvent.postReply());
localReplyNotification.remove(markPostReplyKnownEvent.postReply());
- mentionNotification.remove(markPostReplyKnownEvent.postReply().getPost());
+ mentionNotification.remove(markPostReplyKnownEvent.postReply().getPost().get());
}
/**
localReplyNotification.remove(reply);
if (!getMentionedSones(reply.getText()).isEmpty()) {
boolean isMentioned = false;
- for (PostReply existingReply : getCore().getReplies(reply.getPost())) {
+ for (PostReply existingReply : getCore().getReplies(reply.getPost().get())) {
isMentioned |= !reply.isKnown() && !getMentionedSones(existingReply.getText()).isEmpty();
}
if (!isMentioned) {
- mentionNotification.remove(reply.getPost());
+ mentionNotification.remove(reply.getPost().get());
}
}
}
jsonReply.put("id", reply.getId());
jsonReply.put("sone", reply.getSone().getId());
jsonReply.put("post", reply.getPostId());
- jsonReply.put("postSone", reply.getPost().getSone().getId());
+ 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);