return;
}
PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
- postReplyBuilder.withId(replyId).from(sone).to(getPost(postId)).withTime(replyTime).withText(replyText);
+ postReplyBuilder.withId(replyId).from(sone).to(postId).withTime(replyTime).withText(replyText);
replies.add(postReplyBuilder.build());
}
return null;
}
PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
- postReplyBuilder.randomId().from(sone).to(post).currentTime().withText(text.trim());
+ postReplyBuilder.randomId().from(sone).to(post.getId()).currentTime().withText(text.trim());
final PostReply reply = postReplyBuilder.build();
synchronized (replies) {
replies.put(reply.getId(), reply);
try {
PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
/* TODO - parse time correctly. */
- postReplyBuilder.withId(replyId).from(sone).to(core.getPost(replyPostId)).withTime(Long.parseLong(replyTime)).withText(replyText);
+ postReplyBuilder.withId(replyId).from(sone).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
replies.add(postReplyBuilder.build());
} catch (NumberFormatException nfe1) {
/* TODO - mark Sone as bad. */
/**
* Sets the post this reply refers to.
*
- * @param post
- * The post this reply refers to
+ * @param postId
+ * The ID of the post to reply to
* @return This reply
*/
- public PostReply setPost(Post post);
+ public PostReply setPost(String postId);
}
* Configures this builder to set the given post as post the created reply
* refers to.
*
- * @param post
- * The post the reply refers to
+ * @param postId
+ * The ID of the post the reply refers to
* @return This builder
*/
- public PostReplyBuilder to(Post post);
+ public PostReplyBuilder to(String postId);
/**
* Verifies the configuration of this builder and creates a new post reply.
* have been called.</li>
* <li>The {@link #withText(String) text} must not be {@code null} and must
* contain something other than whitespace.</li>
- * <li>The {@link #to(Post) post} have been set.</li>
+ * <li>The {@link #to(String) post} have been set.</li>
* </ul>
*
* @return The created post reply
package net.pterodactylus.sone.data.impl;
+import net.pterodactylus.sone.core.PostProvider;
import net.pterodactylus.sone.data.PostReplyBuilder;
import net.pterodactylus.sone.data.PostReplyBuilderFactory;
+import com.google.inject.Inject;
+
/**
* {@link PostReplyBuilderFactory} that creates {@link PostReplyBuilderImpl}s.
*
*/
public class DefaultPostReplyBuilderFactory implements PostReplyBuilderFactory {
+ /** The post provider. */
+ private final PostProvider postProvider;
+
+ /**
+ * Creates a new default post reply builder factory.
+ *
+ * @param postProvider
+ * The post provider
+ */
+ @Inject
+ public DefaultPostReplyBuilderFactory(PostProvider postProvider) {
+ this.postProvider = postProvider;
+ }
+
/**
* {@inheritDoc}
*/
@Override
public PostReplyBuilder newPostReplyBuilder() {
- return new PostReplyBuilderImpl();
+ return new PostReplyBuilderImpl(postProvider);
}
}
import java.util.UUID;
-import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.core.PostProvider;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.PostReplyBuilder;
*/
public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder> implements PostReplyBuilder {
- /** The post the created reply refers to. */
- private Post post;
+ /** The post builder. */
+ private final PostProvider postProvider;
+
+ /** The ID of the post the created reply refers to. */
+ private String postId;
+
+ /**
+ * Creates a new post reply builder.
+ *
+ * @param postProvider
+ * The post provider
+ */
+ public PostReplyBuilderImpl(PostProvider postProvider) {
+ this.postProvider = postProvider;
+ }
/**
* {@inheritDoc}
*/
@Override
- public PostReplyBuilder to(Post post) {
- this.post = post;
+ public PostReplyBuilder to(String postId) {
+ this.postId = postId;
return this;
}
checkState(sender != null, "sender must not be null");
checkState((currentTime && (time == 0)) || (!currentTime && (time >= 0)), "either current time or custom time must be set");
checkState(!StringUtils.isBlank(text), "text must not be empty");
- checkState(post != null, "post must not be null");
+ checkState(postId != null, "post must not be null");
/* create new post reply. */
- PostReplyImpl postReplyImpl = new PostReplyImpl(randomId ? UUID.randomUUID().toString() : id);
+ PostReplyImpl postReplyImpl = new PostReplyImpl(postProvider, randomId ? UUID.randomUUID().toString() : id);
postReplyImpl.setSone(sender);
- postReplyImpl.setPost(post);
+ postReplyImpl.setPost(postId);
postReplyImpl.setTime(currentTime ? System.currentTimeMillis() : time);
postReplyImpl.setText(text);
return postReplyImpl;
package net.pterodactylus.sone.data.impl;
-import java.util.UUID;
-
+import net.pterodactylus.sone.core.PostProvider;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Sone;
/**
* Simple {@link PostReply} implementation.
*/
public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
- /** The Post this reply refers to. */
- private volatile Post post;
+ /** The post provider. */
+ private final PostProvider postProvider;
- /**
- * Creates a new reply.
- *
- * @param id
- * The ID of the reply
- */
- public PostReplyImpl(String id) {
- this(id, null, null, 0, null);
- }
+ /** The Post this reply refers to. */
+ private volatile String postId;
/**
* Creates a new reply.
*
- * @param sone
- * The sone that posted the reply
- * @param post
- * The post to reply to
- * @param text
- * The text of the reply
- */
- public PostReplyImpl(Sone sone, Post post, String text) {
- this(sone, post, System.currentTimeMillis(), text);
- }
-
- /**
- * Creates a new reply-
- *
- * @param sone
- * The sone that posted the reply
- * @param post
- * The post to reply to
- * @param time
- * The time of the reply
- * @param text
- * The text of the reply
- */
- public PostReplyImpl(Sone sone, Post post, long time, String text) {
- this(UUID.randomUUID().toString(), sone, post, time, text);
- }
-
- /**
- * Creates a new reply-
- *
- * @param sone
- * The sone that posted the reply
+ * @param postProvider
+ * The post provider
* @param id
* The ID of the reply
- * @param post
- * The post to reply to
- * @param time
- * The time of the reply
- * @param text
- * The text of the reply
*/
- public PostReplyImpl(String id, Sone sone, Post post, long time, String text) {
- super(id, sone, time, text);
- this.post = post;
+ public PostReplyImpl(PostProvider postProvider, String id) {
+ super(id);
+ this.postProvider = postProvider;
+ this.postId = postId;
}
//
*/
@Override
public Post getPost() {
- return post;
+ return postProvider.getPost(postId);
}
/**
* Sets the post this reply refers to.
*
- * @param post
- * The post this reply refers to
+ * @param postId
+ * The ID of the post to reply to
* @return This reply (for method chaining)
*/
@Override
- public PostReply setPost(Post post) {
- this.post = post;
+ public PostReply setPost(String postId) {
+ this.postId = postId;
return this;
}
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.core.FreenetInterface;
+import net.pterodactylus.sone.core.PostProvider;
import net.pterodactylus.sone.core.WebOfTrustUpdater;
import net.pterodactylus.sone.data.PostBuilderFactory;
import net.pterodactylus.sone.data.PostReplyBuilderFactory;
bind(FcpInterface.class).in(Singleton.class);
bind(PostBuilderFactory.class).to(DefaultPostBuilderFactory.class).in(Singleton.class);
bind(PostReplyBuilderFactory.class).to(DefaultPostReplyBuilderFactory.class).in(Singleton.class);
+ bind(PostProvider.class).to(Core.class).in(Singleton.class);
bindListener(Matchers.any(), new TypeListener() {
@Override