}
}
- public Optional<PostReply> getPostReply(String replyId) {
- return database.getPostReply(replyId);
- }
-
- public List<PostReply> getReplies(final String postId) {
- return database.getReplies(postId);
- }
-
/**
* Returns all Sones that have liked the given post.
*
post.setKnown(true);
eventBus.post(new MarkPostKnownEvent(post));
touchConfiguration();
- for (PostReply reply : getReplies(post.getId())) {
+ for (PostReply reply : post.getReplies()) {
markReplyKnown(reply);
}
}
package net.pterodactylus.sone.fcp;
+import static com.google.common.collect.FluentIterable.from;
+
import java.util.Collection;
import java.util.List;
import freenet.support.SimpleFieldSet;
import com.google.common.base.Optional;
-import com.google.common.collect.Collections2;
/**
* Abstract base implementation of a {@link Command} with Sone-related helper
protected PostReply getReply(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException {
try {
String replyId = simpleFieldSet.getString(parameterName);
- Optional<PostReply> reply = core.getPostReply(replyId);
+ Optional<PostReply> reply = core.getDatabase().getPostReply(replyId);
if (!reply.isPresent()) {
throw new FcpException("Could not load reply from “" + replyId + "”.");
}
postBuilder.put(encodeLikes(core.getLikes(post), prefix + "Likes."));
if (includeReplies) {
- List<PostReply> replies = core.getReplies(post.getId());
+ List<PostReply> replies = post.getReplies();
postBuilder.put(encodeReplies(replies, prefix));
}
String postPrefix = prefix + postIndex++;
postBuilder.put(encodePost(post, postPrefix + ".", includeReplies));
if (includeReplies) {
- postBuilder.put(encodeReplies(Collections2.filter(core.getReplies(post.getId()), Reply.FUTURE_REPLY_FILTER), postPrefix + "."));
+ postBuilder.put(encodeReplies(from(post.getReplies()).filter(Reply.FUTURE_REPLY_FILTER).toList(), postPrefix + "."));
}
}
package net.pterodactylus.sone.template;
+import static com.google.common.collect.FluentIterable.from;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.util.template.ReflectionAccessor;
import net.pterodactylus.util.template.TemplateContext;
-import com.google.common.collect.Collections2;
-
/**
* Accessor for {@link Post} objects that adds additional properties:
* <dl>
public Object get(TemplateContext templateContext, Object object, String member) {
Post post = (Post) object;
if ("replies".equals(member)) {
- return Collections2.filter(core.getReplies(post.getId()), Reply.FUTURE_REPLY_FILTER);
+ return from(post.getReplies()).filter(Reply.FUTURE_REPLY_FILTER).toList();
} else if (member.equals("likes")) {
return core.getLikes(post);
} else if (member.equals("liked")) {
protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
super.processTemplate(request, templateContext);
String replyId = request.getHttpRequest().getPartAsStringFailsafe("reply", 36);
- Optional<PostReply> reply = webInterface.getCore().getPostReply(replyId);
+ Optional<PostReply> reply = webInterface.getCore().getDatabase().getPostReply(replyId);
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
if (request.getMethod() == Method.POST) {
if (!reply.get().getSone().isLocal()) {
}
webInterface.getCore().markPostKnown(post.get());
} else if (type.equals("reply")) {
- Optional<PostReply> reply = webInterface.getCore().getPostReply(id);
+ Optional<PostReply> reply = webInterface.getCore().getDatabase().getPostReply(id);
if (!reply.isPresent()) {
continue;
}
package net.pterodactylus.sone.web;
+import static com.google.common.collect.FluentIterable.from;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Collections2;
-import com.google.common.collect.FluentIterable;
import com.google.common.collect.Ordering;
/**
List<Hit<Post>> sortedPostHits = Ordering.from(Hit.DESCENDING_COMPARATOR).sortedCopy(postHits);
/* extract Sones and posts. */
- List<Sone> resultSones = FluentIterable.from(sortedSoneHits).transform(new HitMapper<Sone>()).toList();
- List<Post> resultPosts = FluentIterable.from(sortedPostHits).transform(new HitMapper<Post>()).toList();
+ List<Sone> resultSones = from(sortedSoneHits).transform(new HitMapper<Sone>()).toList();
+ List<Post> resultPosts = from(sortedPostHits).transform(new HitMapper<Post>()).toList();
/* pagination. */
Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("sonePage"), 0));
*/
private String getReplyPostId(String phrase) {
String replyId = phrase.startsWith("reply://") ? phrase.substring(8) : phrase;
- Optional<PostReply> postReply = webInterface.getCore().getPostReply(replyId);
+ Optional<PostReply> postReply = webInterface.getCore().getDatabase().getPostReply(replyId);
if (!postReply.isPresent()) {
return null;
}
if (post.getRecipient().isPresent()) {
postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(post.getRecipient().get()));
}
- for (PostReply reply : Collections2.filter(webInterface.getCore().getReplies(post.getId()), Reply.FUTURE_REPLY_FILTER)) {
+ for (PostReply reply : from(post.getReplies()).filter(Reply.FUTURE_REPLY_FILTER)) {
postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(reply.getSone()));
postString.append(' ').append(reply.getText());
}
if (!post.isPresent() || repliedPosts.containsKey(post.get()) || sone.get().equals(post.get().getSone()) || (sone.get().getId().equals(post.get().getRecipientId().orNull()))) {
continue;
}
- repliedPosts.put(post.get(), webInterface.getCore().getReplies(post.get().getId()));
+ repliedPosts.put(post.get(), post.get().getReplies());
}
List<Post> posts = new ArrayList<Post>(repliedPosts.keySet());
Collections.sort(posts, new Comparator<Post>() {
localReplyNotification.remove(reply);
if (!getMentionedSones(reply.getText()).isEmpty() && reply.getPost().isPresent()) {
boolean isMentioned = false;
- for (PostReply existingReply : getCore().getReplies(reply.getPostId())) {
+ for (PostReply existingReply : reply.getPost().transform(Post.TO_REPLIES).get()) {
isMentioned |= !reply.isKnown() && !getMentionedSones(existingReply.getText()).isEmpty();
}
if (!isMentioned) {
@Override
protected JsonReturnObject createJsonObject(FreenetRequest request) {
String replyId = request.getHttpRequest().getParam("reply");
- Optional<PostReply> reply = webInterface.getCore().getPostReply(replyId);
+ Optional<PostReply> reply = webInterface.getCore().getDatabase().getPostReply(replyId);
if (!reply.isPresent()) {
return createErrorJsonObject("invalid-reply-id");
}
Set<Sone> sones = webInterface.getCore().getLikes(post.get());
return createSuccessJsonObject().put("likes", sones.size()).put("sones", getSones(sones));
} else if ("reply".equals(type)) {
- Optional<PostReply> reply = webInterface.getCore().getPostReply(id);
+ Optional<PostReply> reply = webInterface.getCore().getDatabase().getPostReply(id);
if (!reply.isPresent()) {
return createErrorJsonObject("invalid-reply-id");
}
@Override
protected JsonReturnObject createJsonObject(FreenetRequest request) {
String replyId = request.getHttpRequest().getParam("reply");
- Optional<PostReply> reply = webInterface.getCore().getPostReply(replyId);
+ Optional<PostReply> reply = webInterface.getCore().getDatabase().getPostReply(replyId);
if (!reply.isPresent()) {
return createErrorJsonObject("invalid-reply-id");
}
if (allIds.length() > 0) {
String[] ids = allIds.split(",");
for (String id : ids) {
- Optional<PostReply> reply = webInterface.getCore().getPostReply(id);
+ Optional<PostReply> reply = webInterface.getCore().getDatabase().getPostReply(id);
if (!reply.isPresent()) {
continue;
}
}
core.markPostKnown(post.get());
} else if (type.equals("reply")) {
- Optional<PostReply> reply = core.getPostReply(id);
+ Optional<PostReply> reply = core.getDatabase().getPostReply(id);
if (!reply.isPresent()) {
continue;
}