return;
}
PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
- postReplyBuilder.withId(replyId).from(sone).to(postId).withTime(replyTime).withText(replyText);
+ postReplyBuilder.withId(replyId).from(sone.getId()).to(postId).withTime(replyTime).withText(replyText);
replies.add(postReplyBuilder.build());
}
return null;
}
PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
- postReplyBuilder.randomId().from(sone).to(post.getId()).currentTime().withText(text.trim());
+ postReplyBuilder.randomId().from(sone.getId()).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(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
+ postReplyBuilder.withId(replyId).from(sone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
replies.add(postReplyBuilder.build());
} catch (NumberFormatException nfe1) {
/* TODO - mark Sone as bad. */
* <ul>
* <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
* have been called.</li>
- * <li>The {@link #from(Sone) sender} must not be {@code null}.</li>
+ * <li>The {@link #from(String) sender} must not be {@code null}.</li>
* <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
* have been called.</li>
* <li>The {@link #withText(String) text} must not be {@code null} and must
public B withId(String id);
/**
- * Configures this builder to use the given {@link Sone} as sender of the
- * reply.
+ * Configures this builder to use the ID of the given {@link Sone} as sender
+ * of the reply.
*
- * @param sender
- * The sender of the reply
+ * @param senderId
+ * The ID of the sender of the reply
* @return This builder
*/
- public B from(Sone sender);
+ public B from(String senderId);
/**
* Configures this builder to use the current time when creating the reply.
package net.pterodactylus.sone.data.impl;
import net.pterodactylus.sone.data.ReplyBuilder;
-import net.pterodactylus.sone.data.Sone;
/**
* Abstract implementation of a {@link ReplyBuilder}.
protected String id;
/** The sender of the reply. */
- protected Sone sender;
+ protected String senderId;
/** Whether to use the current time when creating the reply. */
protected boolean currentTime;
*/
@Override
@SuppressWarnings("unchecked")
- public B from(Sone sender) {
- this.sender = sender;
+ public B from(String senderId) {
+ this.senderId = senderId;
return (B) this;
}
package net.pterodactylus.sone.data.impl;
import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.PostReplyBuilder;
import net.pterodactylus.sone.data.PostReplyBuilderFactory;
*/
public class DefaultPostReplyBuilderFactory implements PostReplyBuilderFactory {
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
/** The post provider. */
private final PostProvider postProvider;
/**
* Creates a new default post reply builder factory.
*
+ * @param soneProvider
+ * The Sone provider
* @param postProvider
* The post provider
*/
@Inject
- public DefaultPostReplyBuilderFactory(PostProvider postProvider) {
+ public DefaultPostReplyBuilderFactory(SoneProvider soneProvider, PostProvider postProvider) {
+ this.soneProvider = soneProvider;
this.postProvider = postProvider;
}
*/
@Override
public PostReplyBuilder newPostReplyBuilder() {
- return new PostReplyBuilderImpl(postProvider);
+ return new PostReplyBuilderImpl(soneProvider, postProvider);
}
}
import java.util.UUID;
import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.PostReplyBuilder;
*/
public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder> implements PostReplyBuilder {
- /** The post builder. */
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
+ /** The post provider. */
private final PostProvider postProvider;
/** The ID of the post the created reply refers to. */
/**
* Creates a new post reply builder.
*
+ * @param soneProvider
+ * The Sone provider
* @param postProvider
* The post provider
*/
- public PostReplyBuilderImpl(PostProvider postProvider) {
+ public PostReplyBuilderImpl(SoneProvider soneProvider, PostProvider postProvider) {
+ this.soneProvider = soneProvider;
this.postProvider = postProvider;
}
@Override
public PostReply build() {
checkState((randomId && (id == null)) || (!randomId && (id != null)), "either random ID nor custom ID must be set");
- checkState(sender != null, "sender must not be null");
+ checkState(senderId != 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(postId != null, "post must not be null");
/* create new post reply. */
- return new PostReplyImpl(postProvider, randomId ? UUID.randomUUID().toString() : id, sender, currentTime ? System.currentTimeMillis() : time, text, postId);
+ return new PostReplyImpl(soneProvider, postProvider, randomId ? UUID.randomUUID().toString() : id, senderId, currentTime ? System.currentTimeMillis() : time, text, postId);
}
}
package net.pterodactylus.sone.data.impl;
import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Sone;
/**
* Simple {@link PostReply} implementation.
/**
* Creates a new reply.
*
+ * @param soneProvider
+ * The Sone provider
* @param postProvider
* The post provider
* @param id
* The ID of the reply
- * @param sone
- * The Sone of the reply
+ * @param soneId
+ * The ID of the Sone of the reply
* @param time
* The time of the reply
* @param text
* @param postId
* The ID of the post this reply refers to
*/
- public PostReplyImpl(PostProvider postProvider, String id, Sone sone, long time, String text, String postId) {
- super(id, sone, time, text);
+ public PostReplyImpl(SoneProvider soneProvider, PostProvider postProvider, String id, String soneId, long time, String text, String postId) {
+ super(soneProvider, id, soneId, time, text);
this.postProvider = postProvider;
this.postId = postId;
}
package net.pterodactylus.sone.data.impl;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
*/
public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
/** The ID of the reply. */
private final String id;
/** The Sone that created this reply. */
- private final Sone sone;
+ private final String soneId;
/** The time of the reply. */
private final long time;
/**
* Creates a new reply.
*
+ * @param soneProvider
+ * The Sone provider
* @param id
* The ID of the reply
- * @param sone
- * The Sone of the reply
+ * @param soneId
+ * The ID of the Sone of the reply
* @param time
* The time of the reply
* @param text
* The text of the reply
*/
- protected ReplyImpl(String id, Sone sone, long time, String text) {
+ protected ReplyImpl(SoneProvider soneProvider, String id, String soneId, long time, String text) {
+ this.soneProvider = soneProvider;
this.id = id;
- this.sone = sone;
+ this.soneId = soneId;
this.time = time;
this.text = text;
}
*/
@Override
public Sone getSone() {
- return sone;
+ return soneProvider.getSone(soneId, false);
}
/**
*/
@Override
public String toString() {
- return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]";
+ return String.format("%s[id=%s,sone=%s,time=%d,text=%s]", getClass().getName(), id, soneId, time, text);
}
}
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.core.FreenetInterface;
import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
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(SoneProvider.class).to(Core.class).in(Singleton.class);
bind(PostProvider.class).to(Core.class).in(Singleton.class);
bindListener(Matchers.any(), new TypeListener() {