projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
cf16e1f
)
Make post returned by post reply optional.
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Thu, 24 Jan 2013 06:42:59 +0000
(07:42 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Thu, 24 Jan 2013 06:42:59 +0000
(07:42 +0100)
src/main/java/net/pterodactylus/sone/data/PostReply.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/template/ReplyGroupFilter.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/NewPage.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/WebInterface.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/data/PostReply.java
b/src/main/java/net/pterodactylus/sone/data/PostReply.java
index
8dc6f93
..
36921dd
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/PostReply.java
+++ b/
src/main/java/net/pterodactylus/sone/data/PostReply.java
@@
-37,7
+37,7
@@
public interface PostReply extends Reply<PostReply> {
*
* @return The post this reply refers to
*/
*
* @return The post this reply refers to
*/
- public
Post
getPost();
+ public
Optional<Post>
getPost();
/**
* Sets the post this reply refers to.
/**
* Sets the post this reply refers to.
diff --git
a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java
b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java
index
fa6629e
..
fdedaa0
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java
@@
-21,6
+21,8
@@
import net.pterodactylus.sone.core.PostProvider;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
+import com.google.common.base.Optional;
+
/**
* Simple {@link PostReply} implementation.
*
/**
* Simple {@link PostReply} implementation.
*
@@
-64,8
+66,8
@@
public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
* {@inheritDoc}
*/
@Override
* {@inheritDoc}
*/
@Override
- public
Post
getPost() {
- return postProvider.getPost(postId)
.get()
;
+ public
Optional<Post>
getPost() {
+ return postProvider.getPost(postId);
}
/**
}
/**
diff --git
a/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java
b/src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java
index
1881a1b
..
dbf09a3
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java
+++ b/
src/main/java/net/pterodactylus/sone/notify/ListNotificationFilters.java
@@
-31,6
+31,8
@@
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.util.notify.Notification;
import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.util.notify.Notification;
+import com.google.common.base.Optional;
+
/**
* Filter for {@link ListNotification}s.
*
/**
* Filter for {@link ListNotification}s.
*
@@
-282,11
+284,11
@@
public class ListNotificationFilters {
*/
public static boolean isReplyVisible(Sone sone, PostReply reply) {
checkNotNull(reply, "reply must not be null");
*/
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;
}
return false;
}
- if (!isPostVisible(sone, post)) {
+ if (!isPostVisible(sone, post
.get()
)) {
return false;
}
if (reply.getTime() > System.currentTimeMillis()) {
return false;
}
if (reply.getTime() > System.currentTimeMillis()) {
diff --git
a/src/main/java/net/pterodactylus/sone/template/ReplyGroupFilter.java
b/src/main/java/net/pterodactylus/sone/template/ReplyGroupFilter.java
index
4806cee
..
bcf73d8
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/template/ReplyGroupFilter.java
+++ b/
src/main/java/net/pterodactylus/sone/template/ReplyGroupFilter.java
@@
-29,6
+29,8
@@
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.template.Filter;
import net.pterodactylus.util.template.TemplateContext;
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
/**
* {@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
@@
-48,17
+50,21
@@
public class ReplyGroupFilter implements Filter {
Map<Post, Set<Sone>> postSones = new HashMap<Post, Set<Sone>>();
Map<Post, Set<PostReply>> postReplies = new HashMap<Post, Set<PostReply>>();
for (PostReply reply : allReplies) {
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>();
if (sones == null) {
sones = new HashSet<Sone>();
- postSones.put(post, sones);
+ postSones.put(post
.get()
, sones);
}
sones.add(reply.getSone());
}
sones.add(reply.getSone());
- Set<PostReply> replies = postReplies.get(post);
+ Set<PostReply> replies = postReplies.get(post
.get()
);
if (replies == null) {
replies = new HashSet<PostReply>();
if (replies == null) {
replies = new HashSet<PostReply>();
- postReplies.put(post, replies);
+ postReplies.put(post
.get()
, replies);
}
replies.add(reply);
}
}
replies.add(reply);
}
diff --git
a/src/main/java/net/pterodactylus/sone/web/NewPage.java
b/src/main/java/net/pterodactylus/sone/web/NewPage.java
index
2d4ec55
..
22d27c8
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/NewPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/NewPage.java
@@
-67,7
+67,7
@@
public class NewPage extends SoneTemplatePage {
/* collect new elements from notifications. */
Set<Post> posts = new HashSet<Post>(webInterface.getNewPosts());
for (PostReply reply : webInterface.getNewReplies()) {
/* 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. */
}
/* filter and sort them. */
diff --git
a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
index
dec4fe2
..
5572bca
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
@@
-36,6
+36,8
@@
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Optional;
+
/**
* Lets the user browser another Sone.
*
/**
* Lets the user browser another Sone.
*
@@
-95,11
+97,11
@@
public class ViewSonePage extends SoneTemplatePage {
Set<PostReply> replies = sone.getReplies();
final Map<Post, List<PostReply>> repliedPosts = new HashMap<Post, List<PostReply>>();
for (PostReply reply : replies) {
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;
}
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>() {
}
List<Post> posts = new ArrayList<Post>(repliedPosts.keySet());
Collections.sort(posts, new Comparator<Post>() {
diff --git
a/src/main/java/net/pterodactylus/sone/web/WebInterface.java
b/src/main/java/net/pterodactylus/sone/web/WebInterface.java
index
d9a9dfb
..
3bb11d5
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/WebInterface.java
+++ b/
src/main/java/net/pterodactylus/sone/web/WebInterface.java
@@
-857,8
+857,8
@@
public class WebInterface {
}
if (!hasFirstStartNotification()) {
notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification);
}
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 {
notificationManager.addNotification(mentionNotification);
}
} else {
@@
-900,7
+900,7
@@
public class WebInterface {
public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) {
newReplyNotification.remove(markPostReplyKnownEvent.postReply());
localReplyNotification.remove(markPostReplyKnownEvent.postReply());
public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) {
newReplyNotification.remove(markPostReplyKnownEvent.postReply());
localReplyNotification.remove(markPostReplyKnownEvent.postReply());
- mentionNotification.remove(markPostReplyKnownEvent.postReply().getPost());
+ mentionNotification.remove(markPostReplyKnownEvent.postReply().getPost()
.get()
);
}
/**
}
/**
@@
-940,11
+940,11
@@
public class WebInterface {
localReplyNotification.remove(reply);
if (!getMentionedSones(reply.getText()).isEmpty()) {
boolean isMentioned = false;
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) {
isMentioned |= !reply.isKnown() && !getMentionedSones(existingReply.getText()).isEmpty();
}
if (!isMentioned) {
- mentionNotification.remove(reply.getPost());
+ mentionNotification.remove(reply.getPost()
.get()
);
}
}
}
}
}
}
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
9c4c76f
..
e69aa12
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java
@@
-135,7
+135,7
@@
public class GetStatusAjaxPage extends JsonPage {
jsonReply.put("id", reply.getId());
jsonReply.put("sone", reply.getSone().getId());
jsonReply.put("post", reply.getPostId());
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
().get
Sone().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);
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);