From: David ‘Bombe’ Roden Date: Wed, 16 Oct 2013 19:05:02 +0000 (+0200) Subject: Remove PostReplyProvider methods from Core. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2835d19c0c20dc13fab9371f8cd56984c9114dab;p=Sone.git Remove PostReplyProvider methods from Core. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index fade421..518859c 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -407,14 +407,6 @@ public class Core extends AbstractService implements SoneProvider { } } - public Optional getPostReply(String replyId) { - return database.getPostReply(replyId); - } - - public List 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); } } diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index 19c1979..58be3da 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -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 reply = core.getPostReply(replyId); + Optional 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 replies = core.getReplies(post.getId()); + List 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 + ".")); } } diff --git a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java index 9f33779..74c3d9f 100644 --- a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java @@ -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: *
@@ -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")) { diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java index 7a593bc..f6c86be 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java @@ -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 reply = webInterface.getCore().getPostReply(replyId); + Optional reply = webInterface.getCore().getDatabase().getPostReply(replyId); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); if (request.getMethod() == Method.POST) { if (!reply.get().getSone().isLocal()) { diff --git a/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java b/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java index e89b6dc..98984dd 100644 --- a/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java +++ b/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java @@ -70,7 +70,7 @@ public class MarkAsKnownPage extends SoneTemplatePage { } webInterface.getCore().markPostKnown(post.get()); } else if (type.equals("reply")) { - Optional reply = webInterface.getCore().getPostReply(id); + Optional reply = webInterface.getCore().getDatabase().getPostReply(id); if (!reply.isPresent()) { continue; } diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index f809579..2a4b499 100644 --- a/src/main/java/net/pterodactylus/sone/web/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/SearchPage.java @@ -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> sortedPostHits = Ordering.from(Hit.DESCENDING_COMPARATOR).sortedCopy(postHits); /* extract Sones and posts. */ - List resultSones = FluentIterable.from(sortedSoneHits).transform(new HitMapper()).toList(); - List resultPosts = FluentIterable.from(sortedPostHits).transform(new HitMapper()).toList(); + List resultSones = from(sortedSoneHits).transform(new HitMapper()).toList(); + List resultPosts = from(sortedPostHits).transform(new HitMapper()).toList(); /* pagination. */ Pagination sonePagination = new Pagination(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 = webInterface.getCore().getPostReply(replyId); + Optional 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()); } diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index 4874ade..5e07980 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -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 posts = new ArrayList(repliedPosts.keySet()); Collections.sort(posts, new Comparator() { diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index ed39b71..a72dcd5 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java index c9e493b..c7cbbc1 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java @@ -47,7 +47,7 @@ public class DeleteReplyAjaxPage extends JsonPage { @Override protected JsonReturnObject createJsonObject(FreenetRequest request) { String replyId = request.getHttpRequest().getParam("reply"); - Optional reply = webInterface.getCore().getPostReply(replyId); + Optional reply = webInterface.getCore().getDatabase().getPostReply(replyId); if (!reply.isPresent()) { return createErrorJsonObject("invalid-reply-id"); } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java index 3bb40c9..4838a4e 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java @@ -71,7 +71,7 @@ public class GetLikesAjaxPage extends JsonPage { Set sones = webInterface.getCore().getLikes(post.get()); return createSuccessJsonObject().put("likes", sones.size()).put("sones", getSones(sones)); } else if ("reply".equals(type)) { - Optional reply = webInterface.getCore().getPostReply(id); + Optional reply = webInterface.getCore().getDatabase().getPostReply(id); if (!reply.isPresent()) { return createErrorJsonObject("invalid-reply-id"); } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java index 56b51f4..0f009dc 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -64,7 +64,7 @@ public class GetReplyAjaxPage extends JsonPage { @Override protected JsonReturnObject createJsonObject(FreenetRequest request) { String replyId = request.getHttpRequest().getParam("reply"); - Optional reply = webInterface.getCore().getPostReply(replyId); + Optional reply = webInterface.getCore().getDatabase().getPostReply(replyId); if (!reply.isPresent()) { return createErrorJsonObject("invalid-reply-id"); } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java index b8fc52e..bd51679 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java @@ -78,7 +78,7 @@ public class GetTimesAjaxPage extends JsonPage { if (allIds.length() > 0) { String[] ids = allIds.split(","); for (String id : ids) { - Optional reply = webInterface.getCore().getPostReply(id); + Optional reply = webInterface.getCore().getDatabase().getPostReply(id); if (!reply.isPresent()) { continue; } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java index cb5940c..f79f42e 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java @@ -61,7 +61,7 @@ public class MarkAsKnownAjaxPage extends JsonPage { } core.markPostKnown(post.get()); } else if (type.equals("reply")) { - Optional reply = core.getPostReply(id); + Optional reply = core.getDatabase().getPostReply(id); if (!reply.isPresent()) { continue; }