X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FPostAccessor.java;h=4025c7b4eb47f3d2e95c787d8c1bed5c2dd89359;hb=9b102d5ff09775e3867ad8709f22baf0ad608d30;hp=95dc614e46d9db7e7d875d75d5eaf29e09aff7fc;hpb=0157d6ead52bd7c3052b368bed7026075be7cb33;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java
index 95dc614..4025c7b 100644
--- a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java
+++ b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java
@@ -1,5 +1,5 @@
/*
- * Sone - PostAccessor.java - Copyright © 2010 David Roden
+ * Sone - PostAccessor.java - Copyright © 2010â2019 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,17 +17,14 @@
package net.pterodactylus.sone.template;
-import java.io.IOException;
-import java.io.StringReader;
-
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.text.FreenetLinkParser;
-import net.pterodactylus.sone.text.FreenetLinkParserContext;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
-import net.pterodactylus.util.template.TemplateFactory;
+import net.pterodactylus.util.template.TemplateContext;
+
+import com.google.common.collect.Collections2;
/**
* Accessor for {@link Post} objects that adds additional properties:
@@ -35,14 +32,9 @@ import net.pterodactylus.util.template.TemplateFactory;
*
replies
* All replies to this post, sorted by time, oldest first
*
- *
- * @author David âBombeâ Roden
*/
public class PostAccessor extends ReflectionAccessor {
- /** Parser for Freenet links. */
- private final FreenetLinkParser linkParser;
-
/** The core to get the replies from. */
private final Core core;
@@ -51,41 +43,30 @@ public class PostAccessor extends ReflectionAccessor {
*
* @param core
* The core to get the replies from
- * @param templateFactory
- * The template factory for the text parser
*/
- public PostAccessor(Core core, TemplateFactory templateFactory) {
+ public PostAccessor(Core core) {
this.core = core;
- linkParser = new FreenetLinkParser(templateFactory);
}
/**
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
Post post = (Post) object;
if ("replies".equals(member)) {
- return core.getReplies(post);
+ return Collections2.filter(core.getReplies(post.getId()), Reply.FUTURE_REPLY_FILTER);
} else if (member.equals("likes")) {
return core.getLikes(post);
} else if (member.equals("liked")) {
- Sone currentSone = (Sone) dataProvider.getData("currentSone");
+ Sone currentSone = (Sone) templateContext.get("currentSone");
return (currentSone != null) && (currentSone.isLikedPostId(post.getId()));
} else if (member.equals("new")) {
- return core.isNewPost(post.getId(), false);
- } else if (member.equals("text")) {
- String text = post.getText();
- if (text == null) {
- return null;
- }
- try {
- return linkParser.parse(new FreenetLinkParserContext(post.getSone()), new StringReader(text));
- } catch (IOException ioe1) {
- /* ignore. */
- }
+ return !post.isKnown();
+ } else if (member.equals("bookmarked")) {
+ return core.isBookmarked(post);
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
}