Remove PostReplyProvider methods from Core.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Oct 2013 19:05:02 +0000 (21:05 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:28 +0000 (22:25 +0100)
13 files changed:
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
src/main/java/net/pterodactylus/sone/template/PostAccessor.java
src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java
src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java
src/main/java/net/pterodactylus/sone/web/SearchPage.java
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java

index fade421..518859c 100644 (file)
@@ -407,14 +407,6 @@ public class Core extends AbstractService implements SoneProvider {
                }
        }
 
-       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.
         *
@@ -1176,7 +1168,7 @@ public class Core extends AbstractService implements SoneProvider {
                post.setKnown(true);
                eventBus.post(new MarkPostKnownEvent(post));
                touchConfiguration();
-               for (PostReply reply : getReplies(post.getId())) {
+               for (PostReply reply : post.getReplies()) {
                        markReplyKnown(reply);
                }
        }
index 19c1979..58be3da 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.sone.fcp;
 
+import static com.google.common.collect.FluentIterable.from;
+
 import java.util.Collection;
 import java.util.List;
 
@@ -37,7 +39,6 @@ import freenet.node.FSParseException;
 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
@@ -212,7 +213,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand {
        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 + "”.");
                        }
@@ -309,7 +310,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand {
                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));
                }
 
@@ -338,7 +339,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand {
                        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 + "."));
                        }
                }
 
index 9f33779..74c3d9f 100644 (file)
@@ -17,6 +17,8 @@
 
 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;
@@ -24,8 +26,6 @@ import net.pterodactylus.sone.data.Sone;
 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>
@@ -54,7 +54,7 @@ public class PostAccessor extends ReflectionAccessor {
        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")) {
index 7a593bc..f6c86be 100644 (file)
@@ -52,7 +52,7 @@ public class DeleteReplyPage extends SoneTemplatePage {
        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()) {
index e89b6dc..98984dd 100644 (file)
@@ -70,7 +70,7 @@ public class MarkAsKnownPage extends SoneTemplatePage {
                                }
                                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;
                                }
index f809579..2a4b499 100644 (file)
@@ -17,6 +17,8 @@
 
 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;
@@ -50,7 +52,6 @@ import com.google.common.cache.CacheBuilder;
 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;
 
 /**
@@ -142,8 +143,8 @@ public class SearchPage extends SoneTemplatePage {
                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));
@@ -334,7 +335,7 @@ public class SearchPage extends SoneTemplatePage {
         */
        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;
                }
@@ -458,7 +459,7 @@ public class SearchPage extends SoneTemplatePage {
                        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());
                        }
index 4874ade..5e07980 100644 (file)
@@ -95,7 +95,7 @@ public class ViewSonePage extends SoneTemplatePage {
                        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>() {
index ed39b71..a72dcd5 100644 (file)
@@ -940,7 +940,7 @@ public class WebInterface {
                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) {
index c9e493b..c7cbbc1 100644 (file)
@@ -47,7 +47,7 @@ public class DeleteReplyAjaxPage extends JsonPage {
        @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");
                }
index 3bb40c9..4838a4e 100644 (file)
@@ -71,7 +71,7 @@ public class GetLikesAjaxPage extends JsonPage {
                        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");
                        }
index 56b51f4..0f009dc 100644 (file)
@@ -64,7 +64,7 @@ public class GetReplyAjaxPage extends JsonPage {
        @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");
                }
index b8fc52e..bd51679 100644 (file)
@@ -78,7 +78,7 @@ public class GetTimesAjaxPage extends JsonPage {
                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;
                                }
index cb5940c..f79f42e 100644 (file)
@@ -61,7 +61,7 @@ public class MarkAsKnownAjaxPage extends JsonPage {
                                }
                                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;
                                }