*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
-public class Core extends AbstractService implements SoneProvider, PostProvider {
+public class Core extends AbstractService implements SoneProvider, PostProvider, PostReplyProvider {
/** The logger. */
private static final Logger logger = Logging.getLogger(Core.class);
}
/**
- * Returns the reply with the given ID.
- *
- * @param replyId
- * The ID of the reply to get
- * @return The reply, or {@code null} if there is no such reply
+ * {@inheritDoc}
*/
+ @Override
public PostReply getPostReply(String replyId) {
synchronized (replies) {
return replies.get(replyId);
}
/**
- * Returns all replies for the given post, order ascending by time.
- *
- * @param post
- * The post to get all replies for
- * @return All replies for the given post
+ * {@inheritDoc}
*/
+ @Override
public List<PostReply> getReplies(Post post) {
Set<Sone> sones = getSones();
List<PostReply> replies = new ArrayList<PostReply>();
synchronized (sones) {
final Sone sone = getRemoteSone(identity.getId(), true).setIdentity(identity);
boolean newSone = sone.getRequestUri() == null;
- sone.setRequestUri(getSoneUri(identity.getRequestUri()));
+ sone.setRequestUri(SoneUri.create(identity.getRequestUri()));
sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
if (newSone) {
synchronized (knownSones) {
synchronized (knownPosts) {
for (Post post : sone.getPosts()) {
PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
- postBuilder.copyPost(post).from(storedSone);
+ postBuilder.copyPost(post).from(storedSone.getId());
Post newPost = postBuilder.build().setKnown(knownPosts.contains(post.getId()));
if (!storedPosts.contains(newPost)) {
if (newPost.getTime() < getSoneFollowingTime(sone)) {
Set<PostReply> storedReplies = storedSone.getReplies();
synchronized (knownReplies) {
for (PostReply reply : sone.getReplies()) {
- reply.setSone(storedSone).setKnown(knownReplies.contains(reply.getId()));
+ reply.setKnown(knownReplies.contains(reply.getId()));
if (!storedReplies.contains(reply)) {
if (reply.getTime() < getSoneFollowingTime(sone)) {
knownReplies.add(reply.getId());
logger.log(Level.WARNING, "Invalid post found, aborting load!");
return;
}
- PostBuilder postBuilder = postBuilderFactory.newPostBuilder().withId(postId).from(sone).withTime(postTime).withText(postText);
+ PostBuilder postBuilder = postBuilderFactory.newPostBuilder().withId(postId).from(sone.getId()).withTime(postTime).withText(postText);
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
- postBuilder.to(getSone(postRecipientId));
+ postBuilder.to(postRecipientId);
}
posts.add(postBuilder.build());
}
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;
}
PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
- postBuilder.from(sone).randomId().withTime(time).withText(text.trim());
+ postBuilder.from(sone.getId()).randomId().withTime(time).withText(text.trim());
if (recipient != null) {
- postBuilder.to(recipient);
+ postBuilder.to(recipient.getId());
}
final Post post = postBuilder.build();
synchronized (posts) {
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);
}
/**
- * Generate a Sone URI from the given URI and latest edition.
- *
- * @param uriString
- * The URI to derive the Sone URI from
- * @return The derived URI
- */
- private static FreenetURI getSoneUri(String uriString) {
- try {
- FreenetURI uri = new FreenetURI(uriString).setDocName("Sone").setMetaString(new String[0]);
- return uri;
- } catch (MalformedURLException mue1) {
- logger.log(Level.WARNING, String.format("Could not create Sone URI from URI: %s", uriString), mue1);
- return null;
- }
- }
-
- /**
* Notifies the core that a new {@link OwnIdentity} was added.
*
* @param ownIdentityAddedEvent